class CW::Dsl
Public Class Methods
# 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
# File lib/cw/dsl.rb, line 291 def alpha ; 'a'.upto('z').collect{|ch| ch} ; end
# File lib/cw/dsl.rb, line 198 def alphabet(options = {reverse: nil}) @words.alphabet(options) end
# File lib/cw/dsl.rb, line 153 def beginning_with(* letters) Cfg.config.params["begin"] = letters @words.beginning_with end
# File lib/cw/dsl.rb, line 274 def callsign count = 1 callsign = Callsign.new @words.assign callsign.* count end
# File lib/cw/dsl.rb, line 168 def containing(* letters) Cfg.config.params["containing"] = letters @words.containing end
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
# File lib/cw/dsl.rb, line 210 def cw_element_match arg encs = CW::Encoding.new encs.match_elements arg end
# File lib/cw/dsl.rb, line 294 def dash_letters ; %w(t m o) ; end
# File lib/cw/dsl.rb, line 293 def dot_letters ; %w(e i s h) ; end
# File lib/cw/dsl.rb, line 288 def double_words ; @words.double_words ; end
# File lib/cw/dsl.rb, line 158 def ending_with(* letters) Cfg.config.params["end"] = letters @words.ending_with end
# File lib/cw/dsl.rb, line 163 def including(* letters) Cfg.config.params["including"] = letters @words.including end
# File lib/cw/dsl.rb, line 215 def letter_range args @words.assign alpha Cfg.config.params["including"] = args @words.including end
# File lib/cw/dsl.rb, line 289 def letters_numbers ; @words.letters_numbers ; end
# File lib/cw/dsl.rb, line 302 def list ; Print.new.list self.to_s; puts ; end
# File lib/cw/dsl.rb, line 286 def load_abbreviations ; load_text ABBREVIATIONS ; end
# 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
# File lib/cw/dsl.rb, line 290 def load_codes ; load_text Q_CODES ; end
# File lib/cw/dsl.rb, line 284 def load_common_words ; @words.load 1000 ; end
# File lib/cw/dsl.rb, line 296 def load_consonants ; @words.assign alpha - vowels ; end
# File lib/cw/dsl.rb, line 300 def load_dashes ; load_letters(dash_letters) ; end
# File lib/cw/dsl.rb, line 299 def load_dots ; load_letters(dot_letters) ; end
# File lib/cw/dsl.rb, line 285 def load_most_common_words ; @words.load 500 ; end
# File lib/cw/dsl.rb, line 298 def load_numbers ; @words.assign numbers ; end
# File lib/cw/dsl.rb, line 231 def load_text(filename) Cfg.config.params["dictionary"] = filename @words.load_text filename end
# File lib/cw/dsl.rb, line 295 def load_vowels ; @words.assign vowels ; end
# File lib/cw/dsl.rb, line 236 def load_words(args) @words.load args end
# File lib/cw/dsl.rb, line 177 def no_longer_than(max) @words.no_longer_than max end
# File lib/cw/dsl.rb, line 262 def no_noise Cfg.config.params["noise"] = nil end
# File lib/cw/dsl.rb, line 254 def no_run Cfg.config.params["no_run"] = true end
# File lib/cw/dsl.rb, line 181 def no_shorter_than(min) @words.no_shorter_than min end
# File lib/cw/dsl.rb, line 258 def noise Cfg.config.params["noise"] = true end
# File lib/cw/dsl.rb, line 202 def numbers(options = {reverse: nil}) @words.numbers(options) end
# File lib/cw/dsl.rb, line 206 def numbers_spoken() #todo end
# File lib/cw/dsl.rb, line 244 def print_letters Cfg.config.params["print_letters"] = true end
# File lib/cw/dsl.rb, line 190 def random_letters(options = {}) @words.random_letters(options) end
# File lib/cw/dsl.rb, line 185 def random_letters_numbers(options = {}) options.merge!(letters_numbers: true) @words.random_letters_numbers options end
# File lib/cw/dsl.rb, line 194 def random_numbers(options = {}) @words.random_numbers(options) end
# File lib/cw/dsl.rb, line 279 def read filename = :default Read.new(filename) end
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
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
# File lib/cw/dsl.rb, line 173 def repeat mult @words.repeat mult end
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
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
# File lib/cw/dsl.rb, line 287 def reverse ; @words.reverse ; end
# 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
# File lib/cw/dsl.rb, line 240 def run_default Cfg.config["run_default"] || :test_letters end
# File lib/cw/dsl.rb, line 86 def sending_practice Params.sending_practice = true print_letters (:print_early) end
# File lib/cw/dsl.rb, line 143 def shuffle @words.shuffle unless(ENV["CW_ENV"] == "test") end
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 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
# File lib/cw/dsl.rb, line 301 def to_s ; @str.to_s ; end
# File lib/cw/dsl.rb, line 54 def tx str Cfg.config.params["no_run"] = true Tx.new.tx(str) end
# File lib/cw/dsl.rb, line 266 def use_ebook2cw Cfg.config.params["use_ebook2cw"] = true end
# File lib/cw/dsl.rb, line 270 def use_ruby_tone Cfg.config.params["use_ebook2cw"] = nil end
# File lib/cw/dsl.rb, line 292 def vowels ; %w(a e i o u) ; end
# 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
# 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
# File lib/cw/dsl.rb, line 41 def word_spacing(spacing) Cfg.config.params["word_spacing"] = spacing.to_i end
# File lib/cw/dsl.rb, line 283 def words ; @words.all ; end
# File lib/cw/dsl.rb, line 29 def words= words @words.add words end