Class: CW::Book
Constant Summary
Constants included
from FileDetails
FileDetails::ABBREVIATIONS, FileDetails::AUDIO_DIR, FileDetails::BOOKMARK_FILE, FileDetails::CALLS, FileDetails::CALLS_FILENAME, FileDetails::CODE, FileDetails::CODE_FILENAME, FileDetails::CONFIG_FILENAME, FileDetails::CONFIG_PATH, FileDetails::DASH_FILENAME, FileDetails::DATA, FileDetails::DEF_AUDIO_FILENAME, FileDetails::DICT_DIR, FileDetails::DICT_FILENAME, FileDetails::DOT_AUDIO_DIR, FileDetails::DOT_CW_DIR, FileDetails::DOT_FILENAME, FileDetails::E_SPACE_FILENAME, FileDetails::HERE, FileDetails::Q_CODES, FileDetails::ROOT, FileDetails::SPACE_FILENAME, FileDetails::TEXT, FileDetails::USER_CONFIG_PATH, FileDetails::WORK_DIR
Instance Method Summary
collapse
#audio_dir, #audio_filename, #dash_path, #default_audio_dir, #dot_audio_dir, #dot_cw_dir, #dot_path, #e_space_path, #init_filenames, #process_audio_dir, #process_dot_audio, #process_dot_cw, #progress_file, #space_path, #user_audio_dir
Methods inherited from Tester
#audio_stop, #current_word, #cw_threads, #do_events, #exit!, #exit?, #failed!, #failed?, #finish?, #get_key_input, #get_word_last_char, #init_char_timer, #is_relevant_char?, #key_chr, #key_input, #kill_threads, #monitor_keys, #monitor_keys_thread, #move_word_to_process, #play, #play_words_thread, #print, #print_failed_exit_words, #print_letters?, #print_words, #print_words_exit, #print_words_thread, #print_words_until_quit, #process_letters, #process_space_maybe, #process_word_maybe, #process_words, #push_letter_to_current_word, #quit, #quit?, #quit_key_input?, #reset_stdin, #run, #sleep_char_delay, #stream, #sync_with_audio_player, #sync_with_play, #sync_with_print, #timing, #wait_for_no_word_process, #wait_for_start_sync, #word_proc_timeout
Constructor Details
#initialize(book_details) ⇒ Book
Returns a new instance of Book.
9
10
11
12
13
14
|
# File 'lib/cw/book.rb', line 9
def initialize book_details
init_filenames
@book_details = book_details
read_book book_location
find_sentences
end
|
Instance Method Details
#audio_play_repeat_tone_maybe ⇒ Object
55
56
57
|
# 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 ⇒ Object
108
109
110
111
112
113
|
# 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 ⇒ Object
21
|
# File 'lib/cw/book.rb', line 21
def book_location ; @book_details.book_location ; end
|
#build_word_maybe ⇒ Object
70
71
72
73
74
75
76
77
78
|
# 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?
else
move_word_to_process if complete_word?
end
end
|
#change_or_repeat_sentence? ⇒ Boolean
29
30
31
|
# File 'lib/cw/book.rb', line 29
def change_or_repeat_sentence?
sentence.change_or_repeat?
end
|
#change_repeat_or_quit? ⇒ Boolean
33
34
35
36
37
38
39
40
|
# 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 ⇒ Object
160
161
162
163
164
165
166
167
|
# File 'lib/cw/book.rb', line 160
def check_sentence_count
if @book_details.session_finished?
play.stop
quit
end
end
|
#check_sentence_navigation(chr) ⇒ Object
42
43
44
|
# File 'lib/cw/book.rb', line 42
def check_sentence_navigation chr
sentence.check_sentence_navigation chr
end
|
#compile_and_play ⇒ Object
84
85
86
87
88
|
# File 'lib/cw/book.rb', line 84
def compile_and_play
compile_sentence
play.start_sync()
play.audio.play
end
|
#compile_sentence ⇒ Object
80
81
82
|
# File 'lib/cw/book.rb', line 80
def compile_sentence
play.audio.convert_words(sentence.current + ' ')
end
|
#complete_word? ⇒ Boolean
20
|
# File 'lib/cw/book.rb', line 20
def complete_word? ; get_word_last_char == ' ' ; end
|
#convert ⇒ Object
24
25
26
27
|
# File 'lib/cw/book.rb', line 24
def convert
book = @sentence.all.join
play.audio.convert_book(book)
end
|
#find_sentences ⇒ Object
17
|
# File 'lib/cw/book.rb', line 17
def find_sentences ; sentence.find_all ; end
|
#get_book_progress ⇒ Object
46
47
48
49
|
# 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 ⇒ Object
137
138
139
|
# File 'lib/cw/book.rb', line 137
def make_sentence_index_current
@current_sentence_index = sentence.index
end
|
#next_sentence_or_quit? ⇒ Boolean
def change_and_kill_audio
sentence.change
play.stop
end
95
96
97
98
99
100
101
102
103
104
105
106
|
# 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
sentence.change unless quit?
return true
end
end
|
#play_repeat_tone ⇒ Object
19
|
# File 'lib/cw/book.rb', line 19
def play_repeat_tone ; play.audio.play_tone @repeat_tone ; end
|
#play_sentences_thread ⇒ Object
179
180
181
182
183
|
# 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 ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# 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 ⇒ Object
22
|
# File 'lib/cw/book.rb', line 22
def print_book_advice ; print.print_advice('Play Book') ; end
|
#print_marked_maybe ⇒ Object
124
125
126
127
128
129
130
131
|
# 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?)
else
print.results(@popped) if(@popped && ! print_letters?)
end
end
|
#print_sentences_thread ⇒ Object
185
186
187
188
189
|
# 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 ⇒ Object
169
170
171
172
173
174
175
176
177
|
# 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 ⇒ Object
133
134
135
|
# File 'lib/cw/book.rb', line 133
def print_words_for_current_sentence
print_words(sentence.current)
end
|
59
60
61
62
63
64
65
66
67
68
|
# 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
else
stream.match_last_active_element @process_input_word.strip
end
@process_input_word = @word_to_process = nil
end
end
|
#process_letter(letr) ⇒ Object
119
120
121
122
|
# File 'lib/cw/book.rb', line 119
def process_letter letr
current_word.process_letter letr
sleep_char_delay letr
end
|
115
116
117
|
# File 'lib/cw/book.rb', line 115
def quit_or_process_input?
quit? || @word_to_process
end
|
#read_book(book) ⇒ Object
18
|
# File 'lib/cw/book.rb', line 18
def read_book(book) ; sentence.read_book(book) ; end
|
#sentence ⇒ Object
16
|
# File 'lib/cw/book.rb', line 16
def sentence ; @sentence ||= Sentence.new ; end
|
#sentence_index_current? ⇒ Boolean
141
142
143
|
# File 'lib/cw/book.rb', line 141
def sentence_index_current?
@current_sentence_index && (@current_sentence_index == sentence.index)
end
|
#thread_processes ⇒ Object
191
192
193
194
195
196
|
# File 'lib/cw/book.rb', line 191
def thread_processes
[:monitor_keys_thread,
:play_sentences_thread,
:print_sentences_thread
]
end
|
#write_book_progress ⇒ Object
51
52
53
|
# File 'lib/cw/book.rb', line 51
def write_book_progress
sentence.write_progress progress_file
end
|