class CW::Tester

Public Instance Methods

audio_stop() click to toggle source
# File lib/cw/tester.rb, line 116
def audio_stop
  play.stop if play.still_playing?
end
complete_word?() click to toggle source
# File lib/cw/tester.rb, line 152
def complete_word?
  get_word_last_char == ' '
end
current_word() click to toggle source
# File lib/cw/tester.rb, line 22
def current_word         ; @current_word ||= CurrentWord.new ; end
cw_threads() click to toggle source
# File lib/cw/tester.rb, line 229
def cw_threads
  @cw_threads ||= Threads.new(self, thread_processes)
end
do_events() click to toggle source
# File lib/cw/tester.rb, line 25
def do_events
  sleep 0.005
end
exit!() click to toggle source
# File lib/cw/tester.rb, line 8
def exit!                ; Cfg.config.params["exit"] = true  ; end
exit?() click to toggle source
# File lib/cw/tester.rb, line 9
def exit?                ; Cfg.get_param("exit")             ; end
failed!() click to toggle source
# File lib/cw/tester.rb, line 98
def failed!
  @failed = true
end
failed?() click to toggle source
# File lib/cw/tester.rb, line 94
def failed?
  @failed
end
finish?() click to toggle source
# File lib/cw/tester.rb, line 87
def finish?
  return true if stream.stream_empty?
  return true if timing.print_words_timeout?
  return true if quit?
  false
end
get_key_input() click to toggle source

def start_sync ; @start_sync = true ; end

# File lib/cw/tester.rb, line 16
def get_key_input        ; key_input.read                    ; end
get_word_last_char() click to toggle source
# File lib/cw/tester.rb, line 129
def get_word_last_char
  @input_word.split(//).last(1).first
end
init_char_timer() click to toggle source
# File lib/cw/tester.rb, line 23
def init_char_timer      ; timing.init_char_timer            ; end
is_relevant_char?() click to toggle source
# File lib/cw/tester.rb, line 19
def is_relevant_char?    ; key_input.is_relevant_char?       ; end
key_chr() click to toggle source
# File lib/cw/tester.rb, line 17
def key_chr              ; key_input.char                    ; end
key_input() click to toggle source
# File lib/cw/tester.rb, line 18
def key_input            ; @key_input ||= KeyInput.new       ; end
kill_threads() click to toggle source

def audio ; @audio ||= AudioPlayer.new ; end

# File lib/cw/tester.rb, line 14
def kill_threads         ; @threads.kill                     ; end
monitor_keys() click to toggle source
# File lib/cw/tester.rb, line 250
def monitor_keys
  loop do
    key_input.read
    break if quit_key_input?
    break if quit?
    break if exit?
    check_sentence_navigation(key_chr) if self.class == Book
    build_word_maybe
  end
end
monitor_keys_thread() click to toggle source
# File lib/cw/tester.rb, line 222
def monitor_keys_thread
  monitor_keys
  @key_input = nil
  print "\n\rmonitor keys has quit " if @debug
  exit!
end
move_word_to_process() click to toggle source
# File lib/cw/tester.rb, line 156
def move_word_to_process
  wait_for_no_word_process
  @process_input_word, @input_word = @input_word, ''
  @word_to_process = true
end
play() click to toggle source
# File lib/cw/tester.rb, line 11
def play                 ; @play ||= Play.new(@words)        ; end
play_words_thread() click to toggle source
# File lib/cw/tester.rb, line 209
    def play_words_thread
#      p @words
      play.play_words_until_quit
      print "\n\rplay has quit " if @debug
      exit!
    end
print() click to toggle source
print_failed_exit_words() click to toggle source
print_letters?() click to toggle source
print_words(words) click to toggle source
print_words_exit() click to toggle source
print_words_thread() click to toggle source
print_words_until_quit() click to toggle source
process_letters(letr) click to toggle source
# File lib/cw/tester.rb, line 29
def process_letters letr
  loop do
    do_events
    if self.class == Book
      process_space_maybe(letr) unless @book_details.args[:output] == :letter
      process_word_maybe
      break if change_repeat_or_quit?
      break if timing.char_delay_timeout?
    else
      process_space_maybe(letr) if(self.class == TestWords)
      process_space_maybe(letr) if(self.class == Reveal)
      process_word_maybe
      break if timing.char_delay_timeout?
    end
  end
end
process_space_maybe(letr) click to toggle source
# File lib/cw/tester.rb, line 178
def process_space_maybe letr
  if letr == ' '
    stream.push current_word.strip
    current_word.clear
    letr.clear
    print.success ' ' if print_letters?
  end
end
process_word_maybe() click to toggle source
# File lib/cw/tester.rb, line 67
def process_word_maybe
  print_marked_maybe
  process_input_word_maybe
end
process_words(words) click to toggle source
# File lib/cw/tester.rb, line 46
def process_words words
  book_class = (self.class == Book)
  (words.to_s + ' ').each_char do |letr|
    process_letter letr
    if book_class
      stream.add_char(letr) if @book_details.args[:output] == :letter
    else
      stream.add_char(letr) if(self.class == TestLetters)
    end
    process_letters letr
    print.success letr if print_letters?
    break if(book_class && change_repeat_or_quit?)
    break if ((! book_class) && quit?)
  end
end
push_letter_to_current_word(letr) click to toggle source
# File lib/cw/tester.rb, line 125
def push_letter_to_current_word letr
  current_word.push_letter letr
end
quit() click to toggle source
# File lib/cw/tester.rb, line 6
def quit                 ; Cfg.config.params["quit"] = true  ; end
quit?() click to toggle source
# File lib/cw/tester.rb, line 7
def quit?                ; Cfg.get_param("quit")             ; end
quit_key_input?() click to toggle source
# File lib/cw/tester.rb, line 261
def quit_key_input?
  if key_input.quit_input?
    play.stop
    exit!
    quit
    play.stop
    true
  end
end
reset_stdin() click to toggle source
# File lib/cw/tester.rb, line 21
def reset_stdin          ; key_input.reset_stdin             ; end
run(words) click to toggle source
# File lib/cw/tester.rb, line 242
def run words
  @words = words
  cw_threads.run
  @play = nil
  reset_stdin
  print.newline
end
sleep_char_delay(letr) click to toggle source
# File lib/cw/tester.rb, line 162
def sleep_char_delay letr
  timing.append_char_delay letr, Cfg.config["wpm"], Cfg.config["effective_wpm"]
end
stream() click to toggle source
# File lib/cw/tester.rb, line 20
def stream               ; @stream ||= Stream.new            ; end
sync_with_audio_player() click to toggle source
# File lib/cw/tester.rb, line 120
def sync_with_audio_player
  wait_for_start_sync
  play.wait_player_startup_delay
end
sync_with_play() click to toggle source
# File lib/cw/tester.rb, line 191
def sync_with_play
  loop do
    break if sentence_index_current?
    break if quit?
    sleep 0.015
  end
end
sync_with_print() click to toggle source
# File lib/cw/tester.rb, line 199
def sync_with_print
  loop do
    make_sentence_index_current if ! sentence_index_current?
    break if sentence_index_current?
    break if quit?
    sleep 0.015
    break
  end
end
thread_processes() click to toggle source
# File lib/cw/tester.rb, line 234
def thread_processes
  [
    :monitor_keys_thread,
    :play_words_thread,
    :print_words_thread
  ]
end
timing() click to toggle source
# File lib/cw/tester.rb, line 12
def timing               ; @timing ||= Timing.new            ; end
wait_for_no_word_process() click to toggle source
# File lib/cw/tester.rb, line 142
def wait_for_no_word_process
  word_proc_timeout(:init)
  while @word_to_process
    sleep 0.01
    if word_proc_timeout
      #        Kernel.exit(1)
    end
  end
end
wait_for_start_sync() click to toggle source
# File lib/cw/tester.rb, line 166
def wait_for_start_sync
  timeout = Time.now + 5
  until play.start_sync?
    sleep 0.001
    break if quit?
    if timeout < Time.now
      exit!
      Kernel.exit 1
    end
  end
end
word_proc_timeout(arg = :status) click to toggle source
# File lib/cw/tester.rb, line 133
def word_proc_timeout(arg = :status)
  if arg == :init
    @wp_timeout = Time.now + 5
  else
    return true if(Time.now > @wp_timeout)
  end
  return false
end