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
@@ -0,0 +1,212 @@
1
+ require 'simplecov'
2
+ $VERBOSE = nil #FIXME
3
+ SimpleCov.start
4
+
5
+ require 'minitest/autorun'
6
+ require 'minitest/pride'
7
+ require_relative '../lib/cw'
8
+
9
+ class TestTiming < MiniTest::Test
10
+
11
+ ROOT = File.expand_path File.dirname(__FILE__) + '/../'
12
+
13
+ def setup
14
+ @timing = CWG::Timing.new
15
+ end
16
+
17
+ def teardown
18
+ @timing = nil
19
+ end
20
+
21
+ def test_attr_accessor_delay_time
22
+ @timing.delay_time = 10
23
+ assert_equal 10, @timing.delay_time
24
+ @timing.delay_time = '10'
25
+ assert_equal '10', @timing.delay_time
26
+ end
27
+
28
+ def test_attr_accessor_start_time
29
+ @timing.start_time = 20
30
+ assert_equal 20, @timing.start_time
31
+ @timing.start_time = "text"
32
+ assert_equal "text", @timing.start_time
33
+ end
34
+
35
+ def test_initialize_initializes_delay_time
36
+ assert_equal 0.0, @timing.delay_time
37
+ end
38
+
39
+ def test_initialize_initializes_instance_of_CwEncoding
40
+ assert_equal CWG::CwEncoding, @timing.instance_variable_get(:@cw_encoding).class
41
+ end
42
+
43
+ def test_cw_encoding_returns_an_encoding
44
+ assert_equal [:dot, :dash], @timing.cw_encoding('a')
45
+ assert_equal [:dash,:dash,:dot,:dot], @timing.cw_encoding('z')
46
+ end
47
+
48
+ def test_dot_returns_correct_wpm_timing_for_a_dot
49
+ assert_equal 0.06, @timing.dot(20)
50
+ end
51
+
52
+ def test_dot_ms_returns_correct_ms_for_wpm
53
+ @timing.instance_variable_set(:@wpm, 20)
54
+ assert_equal 0.06, @timing.dot_ms
55
+ end
56
+
57
+ def test_init_print_words_timeout_sets_start_print_time
58
+ time_now = Time.now
59
+ @timing.init_print_words_timeout
60
+ start_time = @timing.instance_variable_get(:@start_print_time)
61
+ assert_in_delta time_now.to_i, start_time.to_i, 1
62
+ end
63
+
64
+ def test_init_print_words_timeout_sets_delay_print_time
65
+ @timing.init_print_words_timeout
66
+ assert_equal 2.0, @timing.instance_variable_get(:@delay_print_time)
67
+ end
68
+
69
+ def test_print_words_timeout
70
+ @timing.instance_variable_set(:@start_print_time, Time.now)
71
+ @timing.instance_variable_set(:@delay_print_time, 2.0)
72
+ assert_equal false, @timing.print_words_timeout?
73
+ @timing.instance_variable_set(:@start_print_time, Time.now - 3)
74
+ @timing.instance_variable_set(:@delay_print_time, 2.0)
75
+ assert_equal true, @timing.print_words_timeout?
76
+ end
77
+
78
+ #todo
79
+ # def test_play_words_timeout
80
+ # @timing.instance_variable_set(:@start_play_time, Time.now)
81
+ # @timing.instance_variable_set(:@delay_play_time, 1)
82
+ # assert_equal false, @timing.play_words_timeout?
83
+ # @timing.instance_variable_set(:@start_play_time, Time.now - 2)
84
+ # @timing.instance_variable_set(:@delay_play_time, 1)
85
+ # assert_equal true, @timing.play_words_timeout?
86
+ # end
87
+
88
+ def test_effective_dot_ms
89
+ @timing.instance_variable_set(:@effective_wpm, 20)
90
+ assert_equal 0.06, @timing.effective_dot_ms
91
+ end
92
+
93
+ def test_init_char_timer
94
+ end
95
+
96
+ def test_init_char_timer_sets_start_time
97
+ time_now = Time.now
98
+ @timing.init_char_timer
99
+ assert_in_delta time_now.to_i, @timing.start_time.to_i, 1
100
+ end
101
+
102
+ def test_init_char_timer_sets_delay_time
103
+ @timing.init_char_timer
104
+ assert_equal 0.0, @timing.delay_time
105
+ end
106
+
107
+ def test_char_delay_timeout
108
+ @timing.start_time = Time.now
109
+ @timing.delay_time = - 1.0
110
+ assert_equal true, @timing.char_delay_timeout?
111
+ end
112
+
113
+ def test_char_delay_timeout_2
114
+ @timing.start_time = Time.now
115
+ @timing.delay_time = + 1.0
116
+ assert_equal false, @timing.char_delay_timeout?
117
+ end
118
+
119
+ def test_char_timing_for_dot
120
+ @timing.instance_variable_set(:@wpm, 20)
121
+ assert_equal 0.06 + (0.06 * 3), @timing.char_timing([:dot])
122
+ end
123
+
124
+ def test_char_timing_for_dash
125
+ @timing.instance_variable_set(:@wpm, 20)
126
+ assert_equal 0.18 + (0.06 * 3), @timing.char_timing([:dash])
127
+ end
128
+
129
+ def test_char_timing_for_dash_dot
130
+ @timing.instance_variable_set(:@wpm, 120)
131
+ assert_equal 0.03 + 0.01 + (0.01 * 3) + (0.01 * 1), @timing.char_timing([:dash, :dot])
132
+ end
133
+
134
+ def test_code_space_timing_with_no_ewpm
135
+ @timing.instance_variable_set(:@wpm, 20)
136
+ assert_equal (0.06 * 3), @timing.code_space_timing
137
+ end
138
+
139
+ def test_code_space_timing_with_ewpm
140
+ @timing.instance_variable_set(:@wpm, 20)
141
+ @timing.instance_variable_set(:@effective_wpm, 10)
142
+ assert_equal (0.12 * 3), @timing.code_space_timing
143
+ end
144
+
145
+ def test_space_timing_with_no_wpm
146
+ @timing.instance_variable_set(:@wpm, 20)
147
+ assert_equal (0.06 * 4), @timing.space_timing
148
+ end
149
+
150
+ def test_space_timing_with_wpm
151
+ @timing.instance_variable_set(:@wpm, 20)
152
+ @timing.instance_variable_set(:@effective_wpm, 10)
153
+ assert_equal (0.12 * 4), @timing.space_timing
154
+ end
155
+
156
+ def test_char_delay_for_letter_e
157
+ assert_equal(0.06 + (3 * 0.06), @timing.char_delay('e', 20, nil))
158
+ end
159
+
160
+ def test_char_delay_for_letter_t
161
+ assert_equal((0.06 * 3) + (3 * 0.06), @timing.char_delay('t', 20, nil))
162
+ end
163
+
164
+ def test_char_delay_for_letter_i
165
+ assert_equal( (( 2 * 0.06)) + (4 * 0.06), @timing.char_delay('i', 20, nil))
166
+ end
167
+
168
+ def test_char_delay_for_letter_m
169
+ assert_equal( (( 2 * 0.18)) + (4 * 0.06), @timing.char_delay('m', 20, nil))
170
+ end
171
+
172
+ def test_char_delay_for_number_5
173
+ assert_equal( (( 5 * 0.06)) + (7 * 0.06), @timing.char_delay('5', 20, nil))
174
+ end
175
+
176
+ def test_char_delay_for_number_0
177
+ assert_equal( (( 5 * 0.18)) + (7 * 0.06), @timing.char_delay('0', 20, nil))
178
+ end
179
+
180
+ def test_char_delay_for_letter_e_with_ewpm
181
+ assert_equal(0.06 + (3 * 0.12), @timing.char_delay('e', 20, 10))
182
+ end
183
+
184
+ def test_char_delay_for_letter_t_with_ewpm
185
+ assert_equal((3 * 0.06) + (3 * 0.12), @timing.char_delay('t', 20, 10))
186
+ end
187
+
188
+ def test_char_delay_for_number_5_with_ewpm
189
+ assert_equal( ((5 * 0.06) + (4 * 0.06)) + (3 * 0.12), @timing.char_delay('5', 20, 10))
190
+ end
191
+
192
+ def test_char_delay_for_number_0_with_ewpm
193
+ assert_equal( ((5 * 0.18) + (4 * 0.06)) + (3 * 0.12), @timing.char_delay('0', 20, 10))
194
+ end
195
+
196
+ def test_append_char_delay_no_ewpm
197
+ assert_equal(0, @timing.delay_time)
198
+ @timing.append_char_delay('m', 20, nil)
199
+ assert_equal( (( 2 * 0.18)) + (4 * 0.06), @timing.delay_time)
200
+ end
201
+
202
+ def test_append_char_delay_for_i_with_ewpm
203
+ @timing.append_char_delay('i', 20, 10)
204
+ assert_equal(( 2 * 0.06) + (1 * 0.06) + (3 * 0.12), @timing.delay_time)
205
+ end
206
+
207
+ def test_append_char_delay_for_m_with_ewpm
208
+ @timing.append_char_delay('m', 20, 10)
209
+ assert_equal((2 * 0.18) + (1 * 0.06) + (3 * 0.12), @timing.delay_time)
210
+ end
211
+
212
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martyn Jago
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: sanitize
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 4.0.1
89
+ version: 4.1.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 4.0.1
96
+ version: 4.1.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: wavefile
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.7.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: parseconfig
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.8
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.0.8
125
+ - !ruby/object:Gem::Dependency
126
+ name: os
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.9.6
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.9.6
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: version
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +178,48 @@ dependencies:
150
178
  - - ">="
151
179
  - !ruby/object:Gem::Version
152
180
  version: 0.12.0
181
+ - !ruby/object:Gem::Dependency
182
+ name: yard
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 0.9.5
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 0.9.5
195
+ - !ruby/object:Gem::Dependency
196
+ name: sequel
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: sqlite3
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
153
223
  description: A ruby library to help learn and practice morse code
154
224
  email:
155
225
  - martyn.jago@btinternet.com
@@ -159,24 +229,25 @@ extensions: []
159
229
  extra_rdoc_files: []
160
230
  files:
161
231
  - ".codeclimate.yml"
232
+ - ".cw_config"
162
233
  - ".gitignore"
163
234
  - ".travis.yml"
164
- - ".yardoc/checksums"
165
- - ".yardoc/object_types"
166
- - ".yardoc/objects/root.dat"
167
235
  - ".yardoc/proxy_types"
168
236
  - Gemfile
169
237
  - LICENSE
170
238
  - README.md
171
239
  - Rakefile
172
240
  - VERSION
241
+ - Vagrantfile
173
242
  - audio/.gitkeep
174
243
  - bin/cw
175
244
  - cw.gemspec
176
245
  - data/text/abbreviations.txt
177
246
  - data/text/book.txt
247
+ - data/text/book_to_read.txt
178
248
  - data/text/common_words.txt
179
249
  - data/text/cw_conversation.txt
250
+ - data/text/english.txt
180
251
  - data/text/most_common_words.txt
181
252
  - data/text/q_codes.txt
182
253
  - example.rb
@@ -186,7 +257,8 @@ files:
186
257
  - lib/cw/book.rb
187
258
  - lib/cw/book_details.rb
188
259
  - lib/cw/cl.rb
189
- - lib/cw/config_file.rb
260
+ - lib/cw/common_words.rb
261
+ - lib/cw/config.rb
190
262
  - lib/cw/current_word.rb
191
263
  - lib/cw/cw_dsl.rb
192
264
  - lib/cw/cw_encoding.rb
@@ -195,9 +267,9 @@ files:
195
267
  - lib/cw/element.rb
196
268
  - lib/cw/file_details.rb
197
269
  - lib/cw/key_input.rb
198
- - lib/cw/monitor_keys.rb
199
270
  - lib/cw/numbers.rb
200
- - lib/cw/params.rb
271
+ - lib/cw/os.rb
272
+ - lib/cw/play.rb
201
273
  - lib/cw/print.rb
202
274
  - lib/cw/process.rb
203
275
  - lib/cw/progress.rb
@@ -218,9 +290,19 @@ files:
218
290
  - lib/cw/tone_helpers.rb
219
291
  - lib/cw/voice.rb
220
292
  - lib/cw/words.rb
293
+ - run_script_tests.rb
294
+ - test/my_words.txt
295
+ - test/test_common_words.rb
296
+ - test/test_config.rb
297
+ - test/test_current_word.rb
221
298
  - test/test_cw.rb
299
+ - test/test_cw_threads.rb
300
+ - test/test_filtering.rb
301
+ - test/test_params.rb
302
+ - test/test_play.rb
222
303
  - test/test_stream.rb
223
304
  - test/test_tester.rb
305
+ - test/test_timing.rb
224
306
  homepage: http://martynjago.co.uk/CW/
225
307
  licenses:
226
308
  - MIT
@@ -244,7 +326,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
326
  version: '0'
245
327
  requirements: []
246
328
  rubyforge_project:
247
- rubygems_version: 2.5.1
329
+ rubygems_version: 2.6.6
248
330
  signing_key:
249
331
  specification_version: 4
250
332
  summary: CW tutor / exerciser
@@ -1,69 +0,0 @@
1
- class ConfigFile
2
-
3
- CONFIG = ".cw_config"
4
- HERE = File.dirname(__FILE__) + '/'
5
- CONFIGS = ['wpm', 'book_name', 'book_dir',
6
- 'play_command', 'success_colour', 'fail_colour',
7
- 'list_colour', 'ebook2cw_path']
8
-
9
- attr_reader :config
10
-
11
- def config
12
- @config ||= Hash.new
13
- end
14
-
15
- def readlines f
16
- f.readlines
17
- end
18
-
19
- def write_config(cfg, line)
20
- config[cfg.to_sym] = line.gsub(cfg + ':', '').strip
21
- end
22
-
23
- def match_config?(line, cfg)
24
- if line
25
- tmp = line.strip()[0, cfg.length]
26
- return true if(tmp == cfg)
27
- end
28
- false
29
- end
30
-
31
- def extract_config line
32
- CONFIGS.each do |cfg|
33
- if match_config?(line, cfg + ':')
34
- write_config(cfg, line)
35
- return
36
- end
37
- end
38
- end
39
-
40
- def read_config
41
- File.open(CONFIG,'r') do |f|
42
- lines = readlines(f)
43
- lines.each do |line|
44
- extract_config line
45
- end
46
- end
47
- end
48
-
49
- def read_config_maybe
50
- if File.exist?(CONFIG)
51
- puts 'Loading config.'
52
- read_config
53
- config
54
- end
55
- end
56
-
57
- def apply_config(sf)
58
- cfg = read_config_maybe
59
- if cfg
60
- cfg.each_pair do |method, arg|
61
- begin
62
- sf.send("#{method}", arg)
63
- rescue
64
- end
65
- Params.send("#{method}=", arg)
66
- end
67
- end
68
- end
69
- end