Module: SpeedRead
- Defined in:
- lib/speed_read.rb,
lib/speed_read/version.rb
Constant Summary collapse
- ORP_VISUAL_POS =
20- VERSION =
"0.0.2"
Class Method Summary collapse
- .colorize_word(word, i) ⇒ Object
-
.find_ORP(word) ⇒ Object
ORP: Optical Recognition Point (the red-colored alignment pilot), # the way Spritz probably does it.
- .start(words_per_minute) ⇒ Object
Class Method Details
.colorize_word(word, i) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/speed_read.rb', line 36 def colorize_word(word, i) return "" unless word pre = word[0...i] pivot = word[i] ? word[i].colorize(:red) : "" suffix = word[i+1..-1] "#{pre}#{pivot}#{suffix}" end |
.find_ORP(word) ⇒ Object
ORP: Optical Recognition Point (the red-colored alignment pilot), # the way Spritz probably does it.
30 31 32 33 34 |
# File 'lib/speed_read.rb', line 30 def find_ORP(word) return 0 if word.nil? return 4 if word.length > 13 return [0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3][word.size]; end |
.start(words_per_minute) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/speed_read.rb', line 11 def start(words_per_minute) puts " " * ORP_VISUAL_POS + "v".colorize(:red) ARGF.each do |line| words = line.chomp.split(/(?:-|\s)+/).compact.reject{|e| e.empty?} words.each do |w| word = w.chomp.strip # pad the end of your lines with spaces if they might be shorter than the previous line. i = find_ORP(word); output = " " * (ORP_VISUAL_POS-i) + colorize_word(word,i) print output.ljust(80, " ") + "#{words_per_minute} wpm\r" $stdout.flush sleep (60.0 / words_per_minute.to_i) end end puts end |