cw 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.cw_config +18 -0
  3. data/.gitignore +10 -1
  4. data/LICENSE +2 -1
  5. data/README.md +212 -96
  6. data/Rakefile +15 -2
  7. data/VERSION +1 -1
  8. data/Vagrantfile +45 -0
  9. data/cw.gemspec +6 -1
  10. data/data/text/book_to_read.txt +4 -0
  11. data/data/text/english.txt +10000 -0
  12. data/example.rb +172 -106
  13. data/lib/cw.rb +10 -126
  14. data/lib/cw/alphabet.rb +53 -46
  15. data/lib/cw/audio_player.rb +83 -72
  16. data/lib/cw/book.rb +160 -185
  17. data/lib/cw/book_details.rb +38 -49
  18. data/lib/cw/cl.rb +101 -95
  19. data/lib/cw/common_words.rb +76 -0
  20. data/lib/cw/config.rb +50 -0
  21. data/lib/cw/current_word.rb +23 -24
  22. data/lib/cw/cw_dsl.rb +264 -131
  23. data/lib/cw/cw_encoding.rb +63 -69
  24. data/lib/cw/cw_stream.rb +86 -82
  25. data/lib/cw/cw_threads.rb +132 -22
  26. data/lib/cw/element.rb +60 -54
  27. data/lib/cw/file_details.rb +26 -11
  28. data/lib/cw/key_input.rb +53 -35
  29. data/lib/cw/numbers.rb +26 -19
  30. data/lib/cw/os.rb +13 -0
  31. data/lib/cw/play.rb +92 -0
  32. data/lib/cw/print.rb +102 -100
  33. data/lib/cw/process.rb +3 -0
  34. data/lib/cw/progress.rb +20 -17
  35. data/lib/cw/randomize.rb +56 -52
  36. data/lib/cw/repeat_word.rb +59 -66
  37. data/lib/cw/reveal.rb +32 -31
  38. data/lib/cw/rss.rb +52 -48
  39. data/lib/cw/sentence.rb +83 -76
  40. data/lib/cw/speak.rb +8 -4
  41. data/lib/cw/spoken.rb +8 -4
  42. data/lib/cw/str.rb +62 -30
  43. data/lib/cw/test_letters.rb +20 -28
  44. data/lib/cw/test_words.rb +25 -31
  45. data/lib/cw/tester.rb +219 -226
  46. data/lib/cw/text_helpers.rb +19 -15
  47. data/lib/cw/timing.rb +63 -67
  48. data/lib/cw/tone_generator.rb +176 -153
  49. data/lib/cw/tone_helpers.rb +15 -23
  50. data/lib/cw/voice.rb +12 -8
  51. data/lib/cw/words.rb +136 -106
  52. data/run_script_tests.rb +165 -0
  53. data/test/my_words.txt +1 -0
  54. data/test/test_common_words.rb +71 -0
  55. data/test/test_config.rb +98 -0
  56. data/test/test_current_word.rb +62 -0
  57. data/test/test_cw.rb +87 -120
  58. data/test/test_cw_threads.rb +123 -0
  59. data/test/test_filtering.rb +439 -0
  60. data/test/test_params.rb +28 -0
  61. data/test/test_play.rb +51 -0
  62. data/test/test_stream.rb +83 -83
  63. data/test/test_tester.rb +9 -27
  64. data/test/test_timing.rb +212 -0
  65. metadata +94 -12
  66. data/lib/cw/config_file.rb +0 -69
  67. data/lib/cw/monitor_keys.rb +0 -37
  68. data/lib/cw/params.rb +0 -104
data/example.rb CHANGED
@@ -1,137 +1,203 @@
1
1
  require 'cw'
2
2
 
3
3
  cw do
4
- comment 'read book feed (1 sentence)'
5
- read_book(sentences: 1)
4
+ comment 'test single element letters'
5
+ wpm 15
6
+ load_alphabet :size, 1
7
+ shuffle
8
+ end
9
+
10
+ cw do
11
+ comment 'test 2 element letters'
12
+ wpm 15
13
+ load_alphabet :size, 2
14
+ shuffle
15
+ end
16
+
17
+ cw do
18
+ comment 'test less than 3 element letters'
19
+ wpm 15
20
+ load_alphabet :less_than, 3
21
+ shuffle
22
+ end
23
+
24
+ cw do
25
+ comment 'test 3 element letters'
26
+ wpm 15
27
+ load_alphabet :size, 3
28
+ shuffle
29
+ end
30
+
31
+ cw do
32
+ comment 'test less than 4 element letters'
33
+ wpm 15
34
+ load_alphabet :less_than, 4
35
+ shuffle
36
+ end
37
+
38
+ cw do
39
+ comment 'test 4 element letters'
40
+ wpm 15
41
+ load_alphabet :size, 4
42
+ shuffle
43
+ end
44
+
45
+ cw do
46
+ comment 'test alphabet vowels'
47
+ wpm 15
48
+ load_vowels
49
+ shuffle
50
+ end
51
+
52
+ cw do
53
+ comment 'test letters a..m'
54
+ wpm 18
55
+ load_alphabet("a".."m")
56
+ shuffle
57
+ end
58
+
59
+ cw do
60
+ comment 'test 8 words made with letters a..m - test by letter'
61
+ wpm 18
62
+ containing('a'..'m')
63
+ shuffle
64
+ word_count 8
65
+ end
66
+
67
+ cw do
68
+ comment 'test letters n..z'
69
+ wpm 18
70
+ load_letters('n'..'z')
71
+ shuffle
72
+ end
73
+
74
+ cw do
75
+ comment 'test 8 words made with letters n..z - test by word'
76
+ wpm 18
77
+ containing('n'..'z')
78
+ shuffle
79
+ word_count 8
80
+ test_words
6
81
  end
7
82
 
8
83
  cw do
9
- comment 'read book feed (1 minute)'
10
- read_book(duration: 1)
84
+ comment 'test numbers'
85
+ wpm 20
86
+ load_numbers
87
+ shuffle
88
+ end
89
+
90
+ cw do
91
+ comment 'test alphabet - repeat until correct'
92
+ wpm 25
93
+ load_alphabet
94
+ shuffle
95
+ repeat_word
96
+ end
97
+
98
+ cw do
99
+ comment 'test 8 most common words no longer than 4 letters'
100
+ wpm 20
101
+ load_most_common_words
102
+ shuffle
103
+ no_longer_than 4
104
+ word_count 8
105
+ end
106
+
107
+ cw do
108
+ comment 'test 4 most common words no shorter than 4 letters'
109
+ wpm 20
110
+ load_most_common_words
111
+ shuffle
112
+ no_shorter_than 4
113
+ word_count 8
114
+ end
115
+
116
+ cw do
117
+ comment 'test 8 words including letter sequence "ing"'
118
+ shuffle
119
+ including('ing')
120
+ word_size 6
121
+ end
122
+
123
+ cw do
124
+ comment 'test 8 words having 6 letters - play each word twice'
125
+ shuffle
126
+ word_size 6
127
+ word_count 8
128
+ double_words
11
129
  end
12
130
 
13
131
  cw do
14
- comment 'read rss feed (1 article)'
15
- read_rss(:reuters, 1)
132
+ comment 'test 8 words beginning with "qu" - repeat whole sequence once'
133
+ wpm 20
134
+ shuffle
135
+ beginning_with 'qu'
136
+ word_count 8
137
+ repeat 1
16
138
  end
17
139
 
18
140
  cw do
19
- name 'test straight alphabet'
20
- alphabet
141
+ comment 'test 8 words ending with "tion" - test by word'
142
+ wpm 15
143
+ shuffle
144
+ ending_with 'tion'
145
+ word_count 8
146
+ test_words
147
+ end
148
+
149
+ cw do
150
+ comment 'read one sentence of book'
151
+ wpm 20
152
+ read_book(sentences: 1)
21
153
  end
22
154
 
23
155
  cw do
24
- comment 'test straight numbers'
25
- numbers
156
+ comment 'read rss feed (quote of the day)'
157
+ wpm 18
158
+ read_rss(:quotation, 1)
26
159
  end
27
160
 
28
161
  cw do
29
- wpm 18
30
- ewpm 12
162
+ comment 'test 6 common cw abbreviations'
163
+ wpm 15
31
164
  load_abbreviations
32
165
  shuffle
166
+ word_count 6
33
167
  end
34
168
 
35
169
  cw do
36
- wpm 18
37
- ewpm 12
38
- load_q_codes
170
+ comment "test 8 Q codes by ear (no keyboard test)"
171
+ wpm 20
172
+ load_codes
39
173
  shuffle
174
+ word_count 8
175
+ print_words
40
176
  end
41
177
 
42
- def cw_settings
178
+ cw do
179
+ comment "test 8 words by ear - reveal words at end of test"
180
+ wpm 20
43
181
  shuffle
182
+ word_count 8
183
+ reveal
184
+ end
185
+
186
+ cw do
187
+ comment "reverse alphabet"
188
+ wpm 20
189
+ load_alphabet
190
+ reverse
191
+ end
192
+
193
+ cw do
194
+ comment "load my own word set"
44
195
  wpm 20
45
- ewpm 15
46
- # use_ebook2cw
47
- use_ruby_tone
48
- mark_words
49
- word_count 5
50
- word_size 4
51
- print_letters
52
- puts self.to_s
53
- end
54
-
55
- cw do
56
- comment 'test random letters'
57
- random_letters(size: 4)
58
- cw_settings
59
- end
60
-
61
- cw do
62
- comment 'test random numbers'
63
- # use_ebook2cw
64
- cw_settings
65
- random_numbers(count: 2, size: 5)
66
- end
67
-
68
- cw do
69
- comment 'test random letters numbers'
70
- # use_ebook2cw
71
- cw_settings
72
- random_letters_numbers(count: 2, size: 11)
73
- end
74
-
75
- wpm = 15
76
- ewpm = 12
77
- loop do
78
-
79
- test = cw
80
- # test.use_ebook2cw
81
- test.comment 'test words beginning with b'
82
- test.shuffle
83
- test.wpm wpm
84
- test.effective_wpm ewpm
85
- test.beginning_with 'b'
86
- test.word_size 4
87
- test.word_count 4
88
- puts test.to_s
89
- test.test_words
90
-
91
- test = cw
92
- test.comment 'test words including ing'
93
- # test.use_ebook2cw
94
- test.shuffle
95
- test.wpm wpm
96
- test.effective_wpm ewpm
97
- test.including 'ing'
98
- test.word_count 5
99
- test.test_words
100
-
101
- # test = cw
102
- # test.comment 'test ing'
103
- # test.use_ebook2cw
104
- ## test.shuffle
105
- # test.wpm wpm
106
- # test.effective_wpm ewpm
107
- # test.beginning_with ['f']
108
- # test.word_size 4
109
- # test.word_count 5
110
- # test.test_words
111
- #
112
- # test = cw
113
- # test.comment 'test ing'
114
- # test.use_ruby_tone
115
- ## test.shuffle
116
- # test.wpm wpm
117
- # test.effective_wpm ewpm
118
- # test.beginning_with ['f']
119
- # test.word_size 4
120
- # test.word_count 5
121
- # test.test_words
122
-
123
- # test = cw
124
- # test.comment 'test ing'
125
- # test.shuffle
126
- # test.wpm wpm
127
- # test.effective_wpm ewpm
128
- # test.beginning_with ['j']
129
- # test.word_size 4
130
- # test.word_count 5
131
- # test.test_words
132
- #
133
- wpm += 2
134
- break if wpm >= 24
196
+ load_text("test/my_words.txt")
197
+ shuffle
198
+ word_count 4
135
199
  end
136
200
 
201
+ # See documentation for more details - and more commands.
202
+
137
203
  puts 'done'
data/lib/cw.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require_relative 'cw/file_details'
4
+ require_relative 'cw/config'
5
+ require_relative 'cw/os'
4
6
  require_relative 'cw/process'
5
7
  require_relative 'cw/text_helpers'
6
8
  require_relative 'cw/tone_helpers'
7
9
  require_relative 'cw/element'
8
10
  require_relative 'cw/current_word'
11
+ require_relative 'cw/cw_encoding'
9
12
  require_relative 'cw/cw_dsl'
10
13
  require_relative 'cw/randomize'
11
14
  require_relative 'cw/sentence'
@@ -15,7 +18,6 @@ require_relative 'cw/str'
15
18
  require_relative 'cw/rss'
16
19
  require_relative 'cw/words'
17
20
  require_relative 'cw/cl'
18
- require_relative 'cw/params'
19
21
  require_relative 'cw/key_input'
20
22
  require_relative 'cw/cw_stream'
21
23
  require_relative 'cw/timing'
@@ -24,151 +26,33 @@ require_relative 'cw/audio_player'
24
26
  require_relative 'cw/cw_threads'
25
27
  require_relative 'cw/book_details'
26
28
  require_relative 'cw/tester'
29
+ require_relative 'cw/play'
27
30
  require_relative 'cw/test_words'
28
31
  require_relative 'cw/test_letters'
29
32
  require_relative 'cw/repeat_word'
30
33
  require_relative 'cw/reveal'
31
34
  require_relative 'cw/book'
32
- require_relative 'cw/cw_encoding'
35
+ #require_relative 'cw/tx'
33
36
  require_relative 'cw/tone_generator'
34
37
  require_relative 'cw/progress'
35
- require_relative 'cw/config_file'
36
-
37
- # CW provides Morse code generation functionality
38
+ require_relative 'cw/common_words'
38
39
 
39
40
  def cw &block
40
41
  CW.new do
41
- instance_eval &block
42
+ instance_eval(&block)
42
43
  end
43
44
  end
44
45
 
45
- class CW < CwDsl
46
+ # CW provides Morse code generation functionality
47
+ # Inherits CwDsl
46
48
 
47
- #FIXME dry_run
48
- # attr_accessor :dry_run
49
+ class CW < CWG::CwDsl
49
50
 
50
51
  # Initialize CW class. Eval block if passed in.
51
52
 
52
53
  def initialize(&block)
53
-
54
54
  super
55
-
56
- load_common_words# unless @words.exist?
57
- ConfigFile.new.apply_config self
58
55
  instance_eval(&block) if block
59
56
  run if block
60
57
  end
61
-
62
- # Test user against letters rather than words.
63
- #
64
-
65
- def test_letters
66
- Params.pause = true
67
- test_letters = TestLetters.new
68
- test_letters.run @words
69
- end
70
-
71
- # Test user against complete words rather than letters.
72
- #
73
-
74
- def test_words
75
- Params.pause = true
76
- tw = TestWords.new
77
- tw.run @words
78
- end
79
-
80
- # Repeat word repeats the current word if the word is entered incorrectly (or not entered at all).
81
- #
82
-
83
- def repeat_word
84
- Params.pause = true
85
- repeat_word = RepeatWord.new
86
- repeat_word.run @words
87
- end
88
-
89
- # Reveal words only at end of test.
90
- # Useful for learning to copy `in the head'
91
-
92
- def reveal
93
- Params.pause = true
94
- reveal = Reveal.new
95
- reveal.run @words
96
- end
97
-
98
- # Return string containing name or comment of test.
99
- # @return [String] comment / name
100
-
101
- def to_s
102
- @str.to_s
103
- end
104
-
105
- def list
106
- Print.new.list self.to_s
107
- puts
108
- end
109
-
110
- # Play book using provided arguments.
111
- # @param [Hash] args the options to play book with.
112
- # @option args [Integer] :sentences Number of sentences to play
113
- # @option args [Integer] :duration Number of minutes to play
114
- # @option args [Boolean] :letter Mark by letter if true else mark by word
115
-
116
- def read_book args = {}
117
- Params.pause = true
118
- details = BookDetails.new
119
- details.arguments(args)
120
- book = Book.new details
121
- book.run @words
122
- end
123
-
124
- # Convert book to mp3.
125
-
126
- def convert_book args = {}
127
- details = BookDetails.new
128
- details.arguments(args)
129
- book = Book.new details
130
- Params.pause = true
131
- book.convert
132
- end
133
-
134
- # Reads RSS feed (requires an internet connection). Feed can be one of:
135
- # - bbc:
136
- # - reuters:
137
- # - guardian:
138
- # - quotation:
139
- # @param [Symbol] source The source of the feed.
140
- # @param [Integer] article_count Number of articles to play.
141
-
142
- def read_rss(source, article_count = 3)
143
- Params.pause = true
144
- rss, = Rss.new
145
- rss.read_rss(source, article_count)
146
- loop do
147
- article = rss.next_article
148
- return unless article
149
- @words.assign article
150
- run
151
- end
152
- end
153
-
154
- # Run word test
155
- def run
156
- return if Params.pause
157
- test_words
158
- end
159
-
160
- alias_method :ewpm, :effective_wpm
161
- alias_method :no_run, :pause
162
- alias_method :comment, :name
163
- alias_method :word_length, :word_size
164
- alias_method :word_shuffle, :shuffle
165
- alias_method :having_size_of, :word_size
166
- alias_method :number_of_words, :word_count
167
- alias_method :words_including, :including
168
- alias_method :words_ending_with, :ending_with
169
- alias_method :random_alphanumeric, :random_letters_numbers
170
- alias_method :words_beginning_with, :beginning_with
171
- alias_method :words_no_longer_than, :no_longer_than
172
- alias_method :words_no_shorter_than, :no_shorter_than
173
-
174
58
  end