Added examples.
This commit is contained in:
parent
95509ae031
commit
aa3fa295d9
11 changed files with 529 additions and 0 deletions
27
examples/src/main/java/com/example/ReadingTimeSample.java
Normal file
27
examples/src/main/java/com/example/ReadingTimeSample.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package com.example;
|
||||
|
||||
import net.thauvin.erik.readingtime.ReadingTime;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ReadingTimeSample {
|
||||
public static void main(String[] args) {
|
||||
if (args.length == 1) {
|
||||
final Path text = Path.of(args[0]);
|
||||
try {
|
||||
final ReadingTime rt = new ReadingTime(Files.readString(text));
|
||||
rt.setPostfix("minute to read");
|
||||
rt.setPlural("minutes to read");
|
||||
|
||||
System.out.println("It will take " + rt.calcReadingTime() + ' ' + ReadingTime.wordCount(rt.getText())
|
||||
+ " words and " + ReadingTime.imgCount(rt.getText()) + " images.");
|
||||
} catch (IOException e) {
|
||||
System.err.println("The file could not be read or found.");
|
||||
}
|
||||
} else {
|
||||
System.err.println("Please specify a file as an argument.");
|
||||
}
|
||||
}
|
||||
}
|
23
examples/src/main/kotlin/com/example/ReadingTimeExample.kt
Normal file
23
examples/src/main/kotlin/com/example/ReadingTimeExample.kt
Normal file
|
@ -0,0 +1,23 @@
|
|||
package com.example
|
||||
|
||||
import java.io.File
|
||||
import net.thauvin.erik.readingtime.ReadingTime
|
||||
import net.thauvin.erik.readingtime.ReadingTime.Companion.imgCount
|
||||
import net.thauvin.erik.readingtime.ReadingTime.Companion.wordCount
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
if (args.size == 1) {
|
||||
val text = File(args[0])
|
||||
if (text.exists() && text.canRead()) {
|
||||
val rt = ReadingTime(text.readText())
|
||||
rt.postfix = "minute to read"
|
||||
rt.plural = "minutes to read"
|
||||
|
||||
println("It will take ${rt.calcReadingTime()} ${wordCount(rt.text)} words and ${imgCount(rt.text)} images.")
|
||||
} else {
|
||||
System.err.println("The file could not be read or found.")
|
||||
}
|
||||
} else {
|
||||
System.err.println("Please specify a file as an argument.")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue