Module: SpeedRead

Defined in:
lib/speed_read.rb,
lib/speed_read/version.rb

Constant Summary collapse

ORP_VISUAL_POS =
20
VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.colorize_word(word, i) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/speed_read.rb', line 39

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.



33
34
35
36
37
# File 'lib/speed_read.rb', line 33

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
# File 'lib/speed_read.rb', line 11

def start(words_per_minute)
  puts " " * ORP_VISUAL_POS + "v".colorize(:red)
  ARGF.each do |line|
     words = tokenize(line)
     words.each do |word|
       # pad the end of your lines with spaces if they might be shorter than the previous line.
       orp = find_ORP(word);
       output = " " * (ORP_VISUAL_POS-orp) + colorize_word(word,orp)
       print output.ljust(80, " ") + "#{words_per_minute} wpm\r"
       $stdout.flush
       sleep (60.0 / words_per_minute.to_i)
     end
  end
  puts
end

.tokenize(input) ⇒ Object



27
28
29
# File 'lib/speed_read.rb', line 27

def tokenize(input)
   input.force_encoding("utf-8").chomp.split(/(?:-|\s)+/).compact.reject{|e| e.empty?}
end