Class: CW::Dsl
Direct Known Subclasses
Core
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
Constants included
from Cfg
Cfg::CONFIG_METHODS
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 included from Cfg
config, get_param, reset, reset_if_nil, reset_param, user_config
Constructor Details
#initialize ⇒ Dsl
Returns a new instance of Dsl.
22
23
24
25
26
27
|
# File 'lib/cw/dsl.rb', line 22
def initialize
@words, @cl, @str =
Words.new, Cl.new, Str.new
Cfg.reset
load_common_words
end
|
Instance Method Details
#alpha ⇒ Object
291
|
# File 'lib/cw/dsl.rb', line 291
def alpha ; 'a'.upto('z').collect{|ch| ch} ; end
|
#alphabet(options = {reverse: nil}) ⇒ Object
198
199
200
|
# File 'lib/cw/dsl.rb', line 198
def alphabet(options = {reverse: nil})
@words.alphabet(options)
end
|
#beginning_with(*letters) ⇒ Object
Also known as:
words_beginning_with
153
154
155
156
|
# File 'lib/cw/dsl.rb', line 153
def beginning_with(* letters)
Cfg.config.params["begin"] = letters
@words.beginning_with
end
|
#callsign(count = 1) ⇒ Object
274
275
276
277
|
# File 'lib/cw/dsl.rb', line 274
def callsign count = 1
callsign = Callsign.new
@words.assign callsign.* count
end
|
#containing(*letters) ⇒ Object
168
169
170
171
|
# File 'lib/cw/dsl.rb', line 168
def containing(* letters)
Cfg.config.params["containing"] = letters
@words.containing
end
|
#convert_book(args = {}) ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/cw/dsl.rb', line 108
def convert_book args = {}
details = BookDetails.new
details.arguments(args)
book = Book.new details
Cfg.config.params["no_run"] = true
book.convert
end
|
#cw_element_match(arg) ⇒ Object
210
211
212
213
|
# File 'lib/cw/dsl.rb', line 210
def cw_element_match arg
encs = CW::Encoding.new
encs.match_elements arg
end
|
#dash_letters ⇒ Object
294
|
# File 'lib/cw/dsl.rb', line 294
def dash_letters ; %w(t m o) ; end
|
#dot_letters ⇒ Object
293
|
# File 'lib/cw/dsl.rb', line 293
def dot_letters ; %w(e i s h) ; end
|
#double_words ⇒ Object
288
|
# File 'lib/cw/dsl.rb', line 288
def double_words ; @words.double_words ; end
|
#ending_with(*letters) ⇒ Object
Also known as:
words_ending_with
158
159
160
161
|
# File 'lib/cw/dsl.rb', line 158
def ending_with(* letters)
Cfg.config.params["end"] = letters
@words.ending_with
end
|
#including(*letters) ⇒ Object
Also known as:
words_including
163
164
165
166
|
# File 'lib/cw/dsl.rb', line 163
def including(* letters)
Cfg.config.params["including"] = letters
@words.including
end
|
#letter_range(args) ⇒ Object
215
216
217
218
219
|
# File 'lib/cw/dsl.rb', line 215
def letter_range args
@words.assign alpha
Cfg.config.params["including"] = args
@words.including
end
|
#letters_numbers ⇒ Object
289
|
# File 'lib/cw/dsl.rb', line 289
def letters_numbers ; @words.letters_numbers ; end
|
#list ⇒ Object
302
|
# File 'lib/cw/dsl.rb', line 302
def list ; Print.new.list self.to_s; puts ; end
|
#load_abbreviations ⇒ Object
286
|
# File 'lib/cw/dsl.rb', line 286
def load_abbreviations ; load_text ABBREVIATIONS ; end
|
#load_alphabet(*args) ⇒ Object
Also known as:
load_letters
221
222
223
224
225
226
227
228
229
|
# File 'lib/cw/dsl.rb', line 221
def load_alphabet(* args)
@words.assign alpha if args.empty?
return if args.empty?
if args[0].class == Range
@words.assign letter_range(args)
return
end
@words.assign cw_element_match(args)
end
|
#load_codes ⇒ Object
290
|
# File 'lib/cw/dsl.rb', line 290
def load_codes ; load_text Q_CODES ; end
|
#load_common_words ⇒ Object
284
|
# File 'lib/cw/dsl.rb', line 284
def load_common_words ; @words.load 1000 ; end
|
#load_consonants ⇒ Object
296
|
# File 'lib/cw/dsl.rb', line 296
def load_consonants ; @words.assign alpha - vowels ; end
|
#load_dashes ⇒ Object
300
|
# File 'lib/cw/dsl.rb', line 300
def load_dashes ; load_letters(dash_letters) ; end
|
#load_dots ⇒ Object
299
|
# File 'lib/cw/dsl.rb', line 299
def load_dots ; load_letters(dot_letters) ; end
|
#load_most_common_words ⇒ Object
285
|
# File 'lib/cw/dsl.rb', line 285
def load_most_common_words ; @words.load 500 ; end
|
#load_numbers ⇒ Object
298
|
# File 'lib/cw/dsl.rb', line 298
def load_numbers ; @words.assign numbers ; end
|
#load_text(filename) ⇒ Object
231
232
233
234
|
# File 'lib/cw/dsl.rb', line 231
def load_text(filename)
Cfg.config.params["dictionary"] = filename
@words.load_text filename
end
|
#load_vowels ⇒ Object
295
|
# File 'lib/cw/dsl.rb', line 295
def load_vowels ; @words.assign vowels ; end
|
#load_words(args) ⇒ Object
236
237
238
|
# File 'lib/cw/dsl.rb', line 236
def load_words(args)
@words.load args
end
|
#no_longer_than(max) ⇒ Object
Also known as:
words_no_longer_than
177
178
179
|
# File 'lib/cw/dsl.rb', line 177
def no_longer_than(max)
@words.no_longer_than max
end
|
#no_noise ⇒ Object
262
263
264
|
# File 'lib/cw/dsl.rb', line 262
def no_noise
Cfg.config.params["noise"] = nil
end
|
#no_run ⇒ Object
254
255
256
|
# File 'lib/cw/dsl.rb', line 254
def no_run
Cfg.config.params["no_run"] = true
end
|
#no_shorter_than(min) ⇒ Object
Also known as:
words_no_shorter_than
181
182
183
|
# File 'lib/cw/dsl.rb', line 181
def no_shorter_than(min)
@words.no_shorter_than min
end
|
#noise ⇒ Object
258
259
260
|
# File 'lib/cw/dsl.rb', line 258
def noise
Cfg.config.params["noise"] = true
end
|
#numbers ⇒ Object
202
203
204
|
# File 'lib/cw/dsl.rb', line 202
def numbers(options = {reverse: nil})
@words.numbers(options)
end
|
#numbers_spoken ⇒ Object
206
207
208
|
# File 'lib/cw/dsl.rb', line 206
def numbers_spoken()
end
|
#print_letters ⇒ Object
244
245
246
|
# File 'lib/cw/dsl.rb', line 244
def print_letters
Cfg.config.params["print_letters"] = true
end
|
#random_letters(options = {}) ⇒ Object
190
191
192
|
# File 'lib/cw/dsl.rb', line 190
def random_letters(options = {})
@words.random_letters(options)
end
|
#random_letters_numbers(options = {}) ⇒ Object
Also known as:
random_alphanumeric
185
186
187
188
|
# File 'lib/cw/dsl.rb', line 185
def random_letters_numbers(options = {})
options.merge!(letters_numbers: true)
@words.random_letters_numbers options
end
|
#random_numbers(options = {}) ⇒ Object
194
195
196
|
# File 'lib/cw/dsl.rb', line 194
def random_numbers(options = {})
@words.random_numbers(options)
end
|
#read(filename = :default) ⇒ Object
279
280
281
|
# File 'lib/cw/dsl.rb', line 279
def read filename = :default
Read.new(filename)
end
|
#read_book(args = {}) ⇒ Object
Play book using provided arguments.
97
98
99
100
101
102
103
104
|
# File 'lib/cw/dsl.rb', line 97
def read_book args = {}
Cfg.config.params["no_run"] = true
details = BookDetails.new
details.arguments(args)
book = Book.new details
book.run @words
end
|
Reads RSS feed (requires an internet connection). Feed can be one of:
-
bbc:
-
reuters:
-
guardian:
-
quotation:
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/cw/dsl.rb', line 124
def (source, article_count = 3)
, = .new
if(ENV["CW_ENV"] == "test")
@words.assign ['test', 'rss', 'stub']
return
end
.(source, article_count)
loop do
article = .next_article
return unless article
Cfg.config.params["no_run"] = false
Cfg.config.params["exit"] = false
Cfg.config.params["quit"] = false
@words.assign article
run
end
end
|
#repeat(mult) ⇒ Object
173
174
175
|
# File 'lib/cw/dsl.rb', line 173
def repeat mult
@words.repeat mult
end
|
#repeat_word ⇒ Object
Also known as:
repeat_letter
Repeat word repeats the current word if the word is entered incorrectly (or not entered at all).
71
72
73
74
75
|
# File 'lib/cw/dsl.rb', line 71
def repeat_word
Cfg.config.params["no_run"] = true
repeat_word = RepeatWord.new
repeat_word.run @words
end
|
#reveal ⇒ Object
Reveal words only at end of test. Useful for learning to copy ‘in the head’
80
81
82
83
84
|
# File 'lib/cw/dsl.rb', line 80
def reveal
Cfg.config.params["no_run"] = true
reveal = Reveal.new
reveal.run @words
end
|
#reverse ⇒ Object
287
|
# File 'lib/cw/dsl.rb', line 287
def reverse ; @words.reverse ; end
|
#run ⇒ Object
248
249
250
251
252
|
# File 'lib/cw/dsl.rb', line 248
def run
return if Cfg.config["no_run"]
word_count(Cfg.config["word_count"])unless Cfg.config.params["words_counted"]
self.send run_default
end
|
#run_default ⇒ Object
240
241
242
|
# File 'lib/cw/dsl.rb', line 240
def run_default
Cfg.config["run_default"] || :test_letters
end
|
#sending_practice ⇒ Object
86
87
88
89
|
# File 'lib/cw/dsl.rb', line 86
def sending_practice
Params.sending_practice = true
print_letters (:print_early)
end
|
#shuffle ⇒ Object
Also known as:
word_shuffle
143
144
145
|
# File 'lib/cw/dsl.rb', line 143
def shuffle
@words.shuffle unless(ENV["CW_ENV"] == "test")
end
|
#test_letters ⇒ Object
Test user against letters rather than words.
48
49
50
51
52
|
# File 'lib/cw/dsl.rb', line 48
def test_letters
Cfg.config.params["no_run"] = true
test_letters = TestLetters.new
test_letters.run @words
end
|
#test_words ⇒ Object
Test user against complete words rather than letters.
62
63
64
65
66
|
# File 'lib/cw/dsl.rb', line 62
def test_words
Cfg.config.params["no_run"] = true
tw = TestWords.new
tw.run @words
end
|
#to_s ⇒ Object
301
|
# File 'lib/cw/dsl.rb', line 301
def to_s ; @str.to_s ; end
|
#tx(str) ⇒ Object
54
55
56
57
|
# File 'lib/cw/dsl.rb', line 54
def tx str
Cfg.config.params["no_run"] = true
Tx.new.tx(str)
end
|
#use_ebook2cw ⇒ Object
266
267
268
|
# File 'lib/cw/dsl.rb', line 266
def use_ebook2cw
Cfg.config.params["use_ebook2cw"] = true
end
|
#use_ruby_tone ⇒ Object
270
271
272
|
# File 'lib/cw/dsl.rb', line 270
def use_ruby_tone
Cfg.config.params["use_ebook2cw"] = nil
end
|
#vowels ⇒ Object
292
|
# File 'lib/cw/dsl.rb', line 292
def vowels ; %w(a e i o u) ; end
|
#word_count(wordcount) ⇒ Object
Also known as:
number_of_words
147
148
149
150
151
|
# File 'lib/cw/dsl.rb', line 147
def word_count(wordcount)
Cfg.config.params["word_count"] = wordcount
@words.count wordcount
Cfg.config.params["words_counted"] = true
end
|
#word_size(size = nil) ⇒ Object
Also known as:
word_length, having_size_of
33
34
35
36
37
38
39
|
# File 'lib/cw/dsl.rb', line 33
def word_size(size = nil)
if size
Cfg.config.params["size"] = size
@words.word_size size
end
Cfg.config["size"]
end
|
#word_spacing(spacing) ⇒ Object
41
42
43
|
# File 'lib/cw/dsl.rb', line 41
def word_spacing(spacing)
Cfg.config.params["word_spacing"] = spacing.to_i
end
|
#words ⇒ Object
283
|
# File 'lib/cw/dsl.rb', line 283
def words ; @words.all ; end
|
#words=(words) ⇒ Object
29
30
31
|
# File 'lib/cw/dsl.rb', line 29
def words= words
@words.add words
end
|