First real commit. Setting up for full CI/CD and testing pipeline
This commit is contained in:
39
internal/reader/engine.go
Normal file
39
internal/reader/engine.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package reader
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
MinWPM = 100
|
||||
MaxWPM = 1000
|
||||
)
|
||||
|
||||
// WordDuration calculates how long a word should be displayed
|
||||
// at the specified reading speed.
|
||||
func WordDuration(word string, wpm int) time.Duration {
|
||||
// Enforce supported reading speed limits.
|
||||
if wpm < MinWPM {
|
||||
wpm = MinWPM
|
||||
}
|
||||
|
||||
if wpm > MaxWPM {
|
||||
wpm = MaxWPM
|
||||
}
|
||||
|
||||
// Base duration for one word.
|
||||
duration := time.Minute / time.Duration(wpm)
|
||||
|
||||
// Add pauses for punctuation.
|
||||
switch {
|
||||
case IsSentenceEnding(word):
|
||||
duration += 300 * time.Millisecond
|
||||
case IsPausePunctuation(word):
|
||||
duration += 150 * time.Millisecond
|
||||
}
|
||||
|
||||
// Allow slightly more time for longer words.
|
||||
if RuneLength(word) >= 10 {
|
||||
duration += 50 * time.Millisecond
|
||||
}
|
||||
|
||||
return duration
|
||||
}
|
||||
Reference in New Issue
Block a user