class CW::Book
Public Class Methods
new(book_details)
click to toggle source
# File lib/cw/book.rb, line 9 def initialize book_details init_filenames @book_details = book_details read_book book_location find_sentences end
Public Instance Methods
audio_play_repeat_tone_maybe()
click to toggle source
# File lib/cw/book.rb, line 55 def audio_play_repeat_tone_maybe play_repeat_tone if sentence.repeat? end
await_next_sentence_or_quit()
click to toggle source
# File lib/cw/book.rb, line 108 def await_next_sentence_or_quit loop do break if next_sentence_or_quit? sleep 0.01 end end
book_location()
click to toggle source
# File lib/cw/book.rb, line 21 def book_location ; @book_details.book_location ; end
build_word_maybe()
click to toggle source
# File lib/cw/book.rb, line 70 def build_word_maybe @input_word ||= '' @input_word << key_chr if is_relevant_char? if @book_details.args[:output] == :letter move_word_to_process if is_relevant_char? #todo else move_word_to_process if complete_word? end end
change_or_repeat_sentence?()
click to toggle source
# File lib/cw/book.rb, line 29 def change_or_repeat_sentence? sentence.change_or_repeat? end
change_repeat_or_quit?()
click to toggle source
# File lib/cw/book.rb, line 33 def change_repeat_or_quit? if(change_or_repeat_sentence? || quit?) sentence.index += 1 write_book_progress return true end false end
check_sentence_count()
click to toggle source
# File lib/cw/book.rb, line 160 def check_sentence_count if @book_details.session_finished? play.stop quit # reset_stdin # kill_threads end end
compile_and_play()
click to toggle source
# File lib/cw/book.rb, line 84 def compile_and_play compile_sentence play.start_sync() play.audio.play end
compile_sentence()
click to toggle source
# File lib/cw/book.rb, line 80 def compile_sentence play.audio.convert_words(sentence.current + ' ') end
complete_word?()
click to toggle source
# File lib/cw/book.rb, line 20 def complete_word? ; get_word_last_char == ' ' ; end
convert()
click to toggle source
# File lib/cw/book.rb, line 24 def convert book = @sentence.all.join play.audio.convert_book(book) end
find_sentences()
click to toggle source
# File lib/cw/book.rb, line 17 def find_sentences ; sentence.find_all ; end
get_book_progress()
click to toggle source
# File lib/cw/book.rb, line 46 def get_book_progress sentence.read_progress progress_file @current_sentence_index = sentence.index end
make_sentence_index_current()
click to toggle source
# File lib/cw/book.rb, line 137 def make_sentence_index_current @current_sentence_index = sentence.index end
next_sentence_or_quit?()
click to toggle source
def change_and_kill_audio
sentence.change play.stop
end
# File lib/cw/book.rb, line 95 def next_sentence_or_quit? sleep 0.01 if play.still_playing? sentence.next unless play.still_playing? if change_repeat_or_quit? play.stop # quit #todo sentence.change unless quit? # change_and_kill_audio #todo prn.newline unless quit? return true end end
play_repeat_tone()
click to toggle source
# File lib/cw/book.rb, line 19 def play_repeat_tone ; play.audio.play_tone @repeat_tone ; end
play_sentences_thread()
click to toggle source
# File lib/cw/book.rb, line 179 def play_sentences_thread play_sentences_until_quit print "\n\rplay has quit " if @debug exit! end
play_sentences_until_quit()
click to toggle source
# File lib/cw/book.rb, line 145 def play_sentences_until_quit get_book_progress loop do check_sentence_count sync_with_print audio_play_repeat_tone_maybe sentence.reset_flags compile_and_play await_next_sentence_or_quit break if quit? end print_words_exit end
print_book_advice()
click to toggle source
# File lib/cw/book.rb, line 22 def print_book_advice ; print.print_advice('Play Book') ; end
print_marked_maybe()
click to toggle source
# File lib/cw/book.rb, line 124 def print_marked_maybe @popped = stream.pop_next_marked if @book_details.args[:output] == :letter print.char_result(@popped) if(@popped && ! print_letters?) #todo else print.results(@popped) if(@popped && ! print_letters?) end end
print_sentences_thread()
click to toggle source
# File lib/cw/book.rb, line 185 def print_sentences_thread print_sentences_until_quit print "\n\rprint has quit " if @debug exit! end
print_sentences_until_quit()
click to toggle source
# File lib/cw/book.rb, line 169 def print_sentences_until_quit loop do check_sentence_count sync_with_play break if quit? sync_with_audio_player print_words_for_current_sentence end end
print_words_for_current_sentence()
click to toggle source
# File lib/cw/book.rb, line 133 def print_words_for_current_sentence print_words(sentence.current) end
process_input_word_maybe()
click to toggle source
# File lib/cw/book.rb, line 59 def process_input_word_maybe if @word_to_process if @book_details.args[:output] == :letter stream.match_first_active_element @process_input_word # .strip #todo else stream.match_last_active_element @process_input_word.strip #todo end @process_input_word = @word_to_process = nil end end
process_letter(letr)
click to toggle source
# File lib/cw/book.rb, line 119 def process_letter letr current_word.process_letter letr sleep_char_delay letr end
quit_or_process_input?()
click to toggle source
# File lib/cw/book.rb, line 115 def quit_or_process_input? quit? || @word_to_process end
read_book(book)
click to toggle source
# File lib/cw/book.rb, line 18 def read_book(book) ; sentence.read_book(book) ; end
sentence()
click to toggle source
# File lib/cw/book.rb, line 16 def sentence ; @sentence ||= Sentence.new ; end
sentence_index_current?()
click to toggle source
# File lib/cw/book.rb, line 141 def sentence_index_current? @current_sentence_index && (@current_sentence_index == sentence.index) end
thread_processes()
click to toggle source
# File lib/cw/book.rb, line 191 def thread_processes [:monitor_keys_thread, :play_sentences_thread, :print_sentences_thread ] end
write_book_progress()
click to toggle source
# File lib/cw/book.rb, line 51 def write_book_progress sentence.write_progress progress_file end