Class: CWG::CwDsl

Inherits:
Object
  • Object
show all
Includes:
Params::ParamsSetup
Defined in:
/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb

Direct Known Subclasses

CW

Constant Summary

HERE =
File.dirname(__FILE__) + '/'
TEXT =
HERE + '../../data/text/'
COMMON_WORDS =
TEXT + 'common_words.txt'
MOST_COMMON_WORDS =
TEXT + 'most_common_words.txt'
ABBREVIATIONS =
TEXT + 'abbreviations.txt'
Q_CODES =
TEXT + 'q_codes.txt'

Constants included from Params::ParamsSetup

Params::ParamsSetup::BOOL_CMDS, Params::ParamsSetup::CMDS, Params::ParamsSetup::PRINT_COLOURS, Params::ParamsSetup::VARS

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CwDsl) initialize

Returns a new instance of CwDsl



22
23
24
25
26
27
28
29
30
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 22

def initialize
  @words, @cl, @str =
               Words.new, Cl.new, Str.new
  Params.init_config
  config_defaults
  config_files
  load_common_words# unless @words.exist?
  ConfigFile.new.apply_config self
end

Instance Attribute Details

- (Object) cl

Returns the value of attribute cl



13
14
15
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 13

def cl
  @cl
end

Instance Method Details

- (Object) alpha

todo refactor



264
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 264

def alpha           ; 'a'.upto('z').collect{|ch| ch} ; end

- (Object) alphabet(options = {reverse: nil})



226
227
228
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 226

def alphabet(options = {reverse: nil})
  @words.alphabet(options)
end

- (Object) beginning_with(*letters) Also known as: words_beginning_with



167
168
169
170
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 167

def beginning_with(* letters)
  Params.begin = letters
  @words.beginning_with
end

- (Object) config_defaults



38
39
40
41
42
43
44
45
46
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 38

def config_defaults
  Params.config {
    name           'unnamed'
    wpm            25
    frequency      500
    volume         1
    dictionary     COMMON_WORDS
  }
end

- (Object) config_files



48
49
50
51
52
53
54
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 48

def config_files
  Params.config {
    audio_dir      'audio'
    audio_filename 'audio_output'
    word_filename  'words.txt'
  }
end

- (Object) containing(*letters)



182
183
184
185
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 182

def containing(* letters)
  Params.containing = letters
  @words.containing
end

- (Object) convert_book(args = {})

Convert book to mp3.



131
132
133
134
135
136
137
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 131

def convert_book args = {}
  details = BookDetails.new
  details.arguments(args)
  book = Book.new details
  Params.no_run = true
  book.convert
end

- (Object) double_words



187
188
189
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 187

def double_words
  @words.double_words
end

- (Object) ending_with(*letters) Also known as: words_ending_with



172
173
174
175
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 172

def ending_with(* letters)
  Params.end = letters
  @words.ending_with
end

- (Object) including(*letters) Also known as: words_including



177
178
179
180
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 177

def including(* letters)
  Params.including = letters
  @words.including
end

- (Object) letters_numbers



209
210
211
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 209

def letters_numbers
  @words.letters_numbers
end

- (Object) list



291
292
293
294
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 291

def list
  Print.new.list self.to_s
  puts
end

- (Object) load_abbreviations



254
255
256
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 254

def load_abbreviations
  load_words ABBREVIATIONS
end

- (Object) load_alphabet



267
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 267

def load_alphabet   ; @words.assign alpha            ; end

- (Object) load_common_words



246
247
248
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 246

def load_common_words
  load_words
end

- (Object) load_consonants



268
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 268

def load_consonants ; @words.assign alpha - vowels   ; end

- (Object) load_most_common_words



250
251
252
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 250

def load_most_common_words
  load_words MOST_COMMON_WORDS
end

- (Object) load_numbers



270
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 270

def load_numbers    ; @words.assign numbers          ; end

- (Object) load_q_codes



258
259
260
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 258

def load_q_codes
  load_words Q_CODES
end

- (Object) load_vowels



266
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 266

def load_vowels     ; @words.assign vowels           ; end

- (Object) load_words(filename = COMMON_WORDS)



272
273
274
275
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 272

def load_words(filename = COMMON_WORDS)
  Params.dictionary = filename
  @words.load filename
end

- (Object) no_longer_than(max) Also known as: words_no_longer_than



195
196
197
198
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 195

def no_longer_than(max)
  Params.max = max
  @words.no_longer_than max
end

- (Object) no_shorter_than(min) Also known as: words_no_shorter_than



200
201
202
203
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 200

def no_shorter_than(min)
  Params.min = min
  @words.no_shorter_than min
end

- (Object) numbers



230
231
232
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 230

def numbers(options = {reverse: nil})
  @words.numbers(options)
end

- (Object) numbers_spoken



234
235
236
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 234

def numbers_spoken()
  #todo
end

- (Object) random_letters(options = {})



218
219
220
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 218

def random_letters(options = {})
  @words.random_letters(options)
end

- (Object) random_letters_numbers(options = {}) Also known as: random_alphanumeric



213
214
215
216
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 213

def random_letters_numbers(options = {})
  options.merge!(letters_numbers: true)
  @words.random_letters_numbers options
end

- (Object) random_numbers(options = {})



222
223
224
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 222

def random_numbers(options = {})
  @words.random_numbers(options)
end

- (Object) read_book(args = {})

Play book using provided arguments.

Parameters:

  • args (Hash) (defaults to: {})

    the options to play book with.

Options Hash (args):

  • :sentences (Integer)

    Number of sentences to play

  • :duration (Integer)

    Number of minutes to play

  • :letter (Boolean)

    Mark by letter if true else mark by word



120
121
122
123
124
125
126
127
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 120

def read_book args = {}
  Params.no_run = true
  details = BookDetails.new
  details.arguments(args)
  book = Book.new details

  book.run @words
end

- (Object) read_rss(source, article_count = 3)

Reads RSS feed (requires an internet connection). Feed can be one of:

  • bbc:

  • reuters:

  • guardian:

  • quotation:

Parameters:

  • source (Symbol)

    The source of the feed.

  • article_count (Integer) (defaults to: 3)

    Number of articles to play.



147
148
149
150
151
152
153
154
155
156
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 147

def read_rss(source, article_count = 3)
  rss, = Rss.new
  rss.read_rss(source, article_count)
  loop do
    article = rss.next_article
    return unless article
    @words.assign article
    run
  end
end

- (Object) reload

def add_noise

  Params.noise = true
end


242
243
244
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 242

def reload
  load_words(Params.dictionary)
end

- (Object) repeat(mult)



191
192
193
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 191

def repeat mult
  @words.repeat mult
end

- (Object) repeat_word

Repeat word repeats the current word if the word is entered incorrectly (or not entered at all).



94
95
96
97
98
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 94

def repeat_word
  Params.no_run = true
  repeat_word = RepeatWord.new
  repeat_word.run @words
end

- (Object) reveal

Reveal words only at end of test. Useful for learning to copy `in the head'



103
104
105
106
107
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 103

def reveal
  Params.no_run = true
  reveal = Reveal.new
  reveal.run @words
end

- (Object) reverse



205
206
207
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 205

def reverse
  @words.reverse
end

- (Object) run



300
301
302
303
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 300

def run
  return if Params.no_run
  self.send run_default
end

- (Object) run_default



296
297
298
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 296

def run_default
  Params.run_default ||= :test_letters
end

- (Object) sending_practice



109
110
111
112
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 109

def sending_practice
  Params.sending_practice = true
  print_letters (:print_early)
end

- (Object) set_tone_type(type)



277
278
279
280
281
282
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 277

def set_tone_type(type)
  case type
  when :squarewave, :sawtooth, :sinewave
    Params.tone = type
  end
end

- (Object) shuffle Also known as: word_shuffle



158
159
160
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 158

def shuffle
  @words.shuffle
end

- (Object) test_letters

Test user against letters rather than words.



75
76
77
78
79
80
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 75

def test_letters
  Params.no_run = true
  test_letters = TestLetters.new

  test_letters.run @words
end

- (Object) test_words

Test user against complete words rather than letters.



85
86
87
88
89
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 85

def test_words
  Params.no_run = true
  tw = TestWords.new
  tw.run @words
end

- (String) to_s

Return string containing name or comment of test.

Returns:

  • (String)

    comment / name



287
288
289
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 287

def to_s
  @str.to_s
end

- (Object) tx



32
33
34
35
36
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 32

def tx
  Params.no_run = true
  tx = Tx.new
  tx.run
end

- (Object) vowels



265
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 265

def vowels          ; ['a','e','i','o','u']          ; end

- (Object) word_count(wordcount) Also known as: number_of_words



162
163
164
165
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 162

def word_count(wordcount)
  Params.word_count = wordcount
  @words.count wordcount
end

- (Object) word_size(size = nil) Also known as: word_length, having_size_of



64
65
66
67
68
69
70
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 64

def word_size(size = nil)
  if size
    Params.size = size
    @words.word_size size
  end
  Params.size
end

- (Object) words



56
57
58
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 56

def words
  @words.all
end

- (Object) words=(words)



60
61
62
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_dsl.rb', line 60

def words= words
  @words.add words
end