class CW::Dsl

Public Class Methods

new() click to toggle source
# File lib/cw/dsl.rb, line 22
def initialize
  @words, @cl, @str =
               Words.new, Cl.new, Str.new
  Cfg.reset
  load_common_words# unless @words.exist?
end

Public Instance Methods

alpha() click to toggle source
# File lib/cw/dsl.rb, line 291
def alpha                  ; 'a'.upto('z').collect{|ch| ch} ; end
alphabet(options = {reverse: nil}) click to toggle source
# File lib/cw/dsl.rb, line 198
def alphabet(options = {reverse: nil})
  @words.alphabet(options)
end
beginning_with(* letters) click to toggle source
# File lib/cw/dsl.rb, line 153
def beginning_with(* letters)
  Cfg.config.params["begin"] = letters
  @words.beginning_with
end
Also aliased as: words_beginning_with
callsign(count = 1) click to toggle source
# File lib/cw/dsl.rb, line 274
def callsign count = 1
  callsign = Callsign.new
  @words.assign callsign.* count
end
containing(* letters) click to toggle source
# File lib/cw/dsl.rb, line 168
def containing(* letters)
  Cfg.config.params["containing"] = letters
  @words.containing
end
convert_book(args = {}) click to toggle source

Convert book to mp3.

# 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) click to toggle source
# File lib/cw/dsl.rb, line 210
def cw_element_match arg
  encs = CW::Encoding.new
  encs.match_elements arg
end
dash_letters() click to toggle source
# File lib/cw/dsl.rb, line 294
def dash_letters           ; %w(t m o)                      ; end
dot_letters() click to toggle source
# File lib/cw/dsl.rb, line 293
def dot_letters            ; %w(e i s h)                    ; end
double_words() click to toggle source
# File lib/cw/dsl.rb, line 288
def double_words           ; @words.double_words            ; end
ending_with(* letters) click to toggle source
# File lib/cw/dsl.rb, line 158
def ending_with(* letters)
  Cfg.config.params["end"] = letters
  @words.ending_with
end
Also aliased as: words_ending_with
having_size_of(size = nil)
Alias for: word_size
including(* letters) click to toggle source
# File lib/cw/dsl.rb, line 163
def including(* letters)
  Cfg.config.params["including"] = letters
  @words.including
end
Also aliased as: words_including
letter_range(args) click to toggle source
# File lib/cw/dsl.rb, line 215
def letter_range args
  @words.assign alpha
  Cfg.config.params["including"] = args
  @words.including
end
letters_numbers() click to toggle source
# File lib/cw/dsl.rb, line 289
def letters_numbers        ; @words.letters_numbers         ; end
list() click to toggle source
# File lib/cw/dsl.rb, line 302
def list                   ; Print.new.list self.to_s; puts ; end
load_abbreviations() click to toggle source
# File lib/cw/dsl.rb, line 286
def load_abbreviations     ; load_text ABBREVIATIONS        ; end
load_alphabet(* args) click to toggle source
# 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
Also aliased as: load_letters
load_codes() click to toggle source
# File lib/cw/dsl.rb, line 290
def load_codes             ; load_text Q_CODES              ; end
load_common_words() click to toggle source
# File lib/cw/dsl.rb, line 284
def load_common_words      ; @words.load 1000               ; end
load_consonants() click to toggle source
# File lib/cw/dsl.rb, line 296
def load_consonants        ; @words.assign alpha - vowels   ; end
load_dashes() click to toggle source
# File lib/cw/dsl.rb, line 300
def load_dashes            ; load_letters(dash_letters)     ; end
load_dots() click to toggle source
# File lib/cw/dsl.rb, line 299
def load_dots              ; load_letters(dot_letters)      ; end
load_letters(* args)
Alias for: load_alphabet
load_most_common_words() click to toggle source
# File lib/cw/dsl.rb, line 285
def load_most_common_words ; @words.load 500                ; end
load_numbers() click to toggle source
# File lib/cw/dsl.rb, line 298
def load_numbers           ; @words.assign numbers          ; end
load_text(filename) click to toggle source
# File lib/cw/dsl.rb, line 231
def load_text(filename)
  Cfg.config.params["dictionary"] = filename
  @words.load_text filename
end
load_vowels() click to toggle source
# File lib/cw/dsl.rb, line 295
def load_vowels            ; @words.assign vowels           ; end
load_words(args) click to toggle source
# File lib/cw/dsl.rb, line 236
def load_words(args)
  @words.load args
end
no_longer_than(max) click to toggle source
# File lib/cw/dsl.rb, line 177
def no_longer_than(max)
  @words.no_longer_than max
end
Also aliased as: words_no_longer_than
no_noise() click to toggle source
# File lib/cw/dsl.rb, line 262
def no_noise
  Cfg.config.params["noise"] = nil
end
no_run() click to toggle source
# File lib/cw/dsl.rb, line 254
def no_run
  Cfg.config.params["no_run"] = true
end
no_shorter_than(min) click to toggle source
# File lib/cw/dsl.rb, line 181
def no_shorter_than(min)
  @words.no_shorter_than min
end
Also aliased as: words_no_shorter_than
noise() click to toggle source
# File lib/cw/dsl.rb, line 258
def noise
  Cfg.config.params["noise"] = true
end
number_of_words(wordcount)
Alias for: word_count
numbers(options = {reverse: nil}) click to toggle source
# File lib/cw/dsl.rb, line 202
def numbers(options = {reverse: nil})
  @words.numbers(options)
end
numbers_spoken() click to toggle source
# File lib/cw/dsl.rb, line 206
def numbers_spoken()
  #todo
end
print_letters() click to toggle source
random_alphanumeric(options = {})
random_letters(options = {}) click to toggle source
# File lib/cw/dsl.rb, line 190
def random_letters(options = {})
  @words.random_letters(options)
end
random_letters_numbers(options = {}) click to toggle source
# File lib/cw/dsl.rb, line 185
def random_letters_numbers(options = {})
  options.merge!(letters_numbers: true)
  @words.random_letters_numbers options
end
Also aliased as: random_alphanumeric
random_numbers(options = {}) click to toggle source
# File lib/cw/dsl.rb, line 194
def random_numbers(options = {})
  @words.random_numbers(options)
end
read(filename = :default) click to toggle source
# File lib/cw/dsl.rb, line 279
def read filename = :default
  Read.new(filename)
end
read_book(args = {}) click to toggle source

Play book using provided arguments. @param [Hash] args the options to play book with. @option args [Integer] :sentences Number of sentences to play @option args [Integer] :duration Number of minutes to play @option args [Boolean] :letter Mark by letter if true else mark by word

# 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
read_feed(source, article_count = 3)
Alias for: read_rss
read_rss(source, article_count = 3) click to toggle source

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

  • bbc:

  • reuters:

  • guardian:

  • quotation:

@param [Symbol] source The source of the feed. @param [Integer] article_count Number of articles to play.

# File lib/cw/dsl.rb, line 124
def read_rss(source, article_count = 3)
  rss, = Rss.new
  # don't go online if CW_ENV == test
  if(ENV["CW_ENV"] == "test")
    @words.assign ['test', 'rss', 'stub']
    return
  end
  rss.read_rss(source, article_count)
  loop do
    article = rss.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
Also aliased as: read_feed
repeat(mult) click to toggle source
# File lib/cw/dsl.rb, line 173
def repeat mult
  @words.repeat mult
end
repeat_letter()
Alias for: repeat_word
repeat_word() click to toggle source

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

# 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
Also aliased as: repeat_letter
reveal() click to toggle source

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

# File lib/cw/dsl.rb, line 80
def reveal
  Cfg.config.params["no_run"] = true
  reveal = Reveal.new
  reveal.run @words
end
reverse() click to toggle source
# File lib/cw/dsl.rb, line 287
def reverse                ;  @words.reverse                ; end
run() click to toggle source
# 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() click to toggle source
# File lib/cw/dsl.rb, line 240
def run_default
  Cfg.config["run_default"] || :test_letters
end
sending_practice() click to toggle source
# File lib/cw/dsl.rb, line 86
def sending_practice
  Params.sending_practice = true
  print_letters (:print_early)
end
shuffle() click to toggle source
# File lib/cw/dsl.rb, line 143
def shuffle
  @words.shuffle unless(ENV["CW_ENV"] == "test")
end
Also aliased as: word_shuffle
test_letters() click to toggle source

Test user against letters rather than words.

# 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() click to toggle source

Test user against complete words rather than letters.

# 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() click to toggle source
# File lib/cw/dsl.rb, line 301
def to_s                   ; @str.to_s                      ; end
tx(str) click to toggle source
# File lib/cw/dsl.rb, line 54
def tx str
  Cfg.config.params["no_run"] = true
  Tx.new.tx(str)
end
use_ebook2cw() click to toggle source
# File lib/cw/dsl.rb, line 266
def use_ebook2cw
  Cfg.config.params["use_ebook2cw"] = true
end
use_ruby_tone() click to toggle source
# File lib/cw/dsl.rb, line 270
def use_ruby_tone
  Cfg.config.params["use_ebook2cw"] = nil
end
vowels() click to toggle source
# File lib/cw/dsl.rb, line 292
def vowels                 ; %w(a e i o u)                  ; end
word_count(wordcount) click to toggle source
# 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
Also aliased as: number_of_words
word_length(size = nil)
Alias for: word_size
word_shuffle()
Alias for: shuffle
word_size(size = nil) click to toggle source
# 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
Also aliased as: word_length, having_size_of
word_spacing(spacing) click to toggle source
# File lib/cw/dsl.rb, line 41
def word_spacing(spacing)
  Cfg.config.params["word_spacing"] = spacing.to_i
end
words() click to toggle source
# File lib/cw/dsl.rb, line 283
def words                  ; @words.all                     ; end
words=(words) click to toggle source
# File lib/cw/dsl.rb, line 29
def words= words
  @words.add words
end
words_beginning_with(* letters)
Alias for: beginning_with
words_ending_with(* letters)
Alias for: ending_with
words_including(* letters)
Alias for: including
words_no_longer_than(max)
Alias for: no_longer_than
words_no_shorter_than(min)
Alias for: no_shorter_than