cw 0.0.12 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f96c63ebcba919ae57d460aae5e40a871af17ad1
4
- data.tar.gz: 4df1a6780ff5ae0b2e1f0966171735156061f409
3
+ metadata.gz: 72ccadeafd51d75edae90d0f494a0ccfe735ab1a
4
+ data.tar.gz: 1a975942e7a54e6db6745b2d5b5cd5a3fae176a1
5
5
  SHA512:
6
- metadata.gz: 8d601393c438cb66221a8e427dbb0f723daea1a24db7084435f494903925b444efaaeeb972341f051b501fdb50a3c4ee2b30c55b3eca1269e8444a3cc9e94e77
7
- data.tar.gz: 4ac510de739832dd440d8cbb94dd6937660bd5ed63a2bce83622d0c12bddf814b44973b395d7e75fbb902ac308657e28f68153b3da106a0b9f25e32ba8f402ef
6
+ metadata.gz: 025e1005cadcac8a29d9f31b2c50498c757749982ee32d78045dd1a71ada9b3a005b403076c49c91f2a87fd15734d87c9d4b848a871cb4d2ca2d4cfc1a1177a5
7
+ data.tar.gz: 6aadbbecd1d18c43a864e29c12a066491bba27443ef411db412a2a92afe30ce9fefa55f3fa6279f8e76df461599c0bfb422a072bfee717cb5d3b2c14a41e9902
@@ -0,0 +1,15 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby
8
+ - javascript
9
+ ratings:
10
+ paths:
11
+ - lib/**
12
+ - "**.rb"
13
+ - "**.go"
14
+ exclude_paths:
15
+ - test/**/*
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ - "2.2.0"
5
+ script:
6
+ - ruby test/test_cw.rb
data/README.md CHANGED
@@ -1,14 +1,19 @@
1
- # CW
1
+ [![Gem Version](https://badge.fury.io/rb/cw.svg)](https://badge.fury.io/rb/cw)
2
+ [![Build Status](https://travis-ci.org/mjago/CW.svg?branch=master)](https://travis-ci.org/mjago/CW)
3
+ [![Code Climate](https://codeclimate.com/github/mjago/CW/badges/gpa.svg)](https://codeclimate.com/github/mjago/CW)
2
4
 
3
- CW is a DSL written in Ruby for generating audible morse, allowing for
4
- real-time learning and testing of Morse Code.
5
+ ## CW
5
6
 
6
- CW can read books, rss feeds, common phrases, QSO codes etc, in
7
- addition to generating random words that match some required pattern
8
- (i.e. words_beginning_with 'v')
7
+ CW is a DSL written in the [Ruby](https://www.ruby-lang.org/en/downloads/) language for generating audible morse - allowing for
8
+ real-time learning and testing of Morse Code. Great emphasis is placed on enabling tests to use fresh material each test run, rather than the constant repetition of old material.
9
9
 
10
- CW also allows for real-time marking by indicating correct and
11
- incorrect characters and words typed in real-time.
10
+ CW can read books (and remember where you are), rss feeds (your daily quotation for instance), common phrases, QSO codes etc, in
11
+ addition to generating random words, letters, and numbers that possibly match some required pattern
12
+ (i.e. words_beginning_with 'v').
13
+
14
+ CW also allows for real-time progress marking by indicating correct and incorrect characters and words copied in real-time. A follow mode also exists which prints the output just after it has played it (for `in head' practice).
15
+
16
+ Documentation to follow...
12
17
 
13
18
  # Installation:
14
19
 
@@ -27,7 +32,7 @@ ruby test/test_cw.rb
27
32
 
28
33
  ```
29
34
 
30
- - Note: Currently only tested on OS X, and Ruby v2.0.0 and greater.
35
+ * Note: Currently only tested on OS X, and Ruby v2.0.0 and greater.
31
36
 
32
37
  ```ruby
33
38
 
@@ -70,6 +75,52 @@ ruby test/test_cw.rb
70
75
  shuffle
71
76
  end
72
77
 
78
+
79
+ # ...or instantiate CW...
80
+
81
+ wpm = 16
82
+
83
+ test = CW.new
84
+ test.comment 'test words beginning with b (repeat word)'
85
+ test.shuffle
86
+ test.wpm wpm
87
+ test.beginning_with 'b'
88
+ test.word_size 4
89
+ test.word_count 2
90
+ puts test.to_s
91
+ test.repeat_word
92
+
93
+ test = CW.new
94
+ test.comment 'test words beginning with b (test letters)'
95
+ test.shuffle
96
+ test.wpm wpm
97
+ test.beginning_with 'b'
98
+ test.word_size 4
99
+ test.word_count 2
100
+ puts test.to_s
101
+ test.test_letters
102
+
103
+ test = CW.new
104
+ test.comment 'test words beginning with b (test words)'
105
+ test.shuffle
106
+ test.wpm wpm
107
+ test.beginning_with 'b'
108
+ test.word_size 4
109
+ test.word_count 2
110
+ puts test.to_s
111
+ test.test_words
112
+
113
+ test = CW.new
114
+ test.comment 'test words beginning with b (print letters)'
115
+ test.shuffle
116
+ test.wpm wpm
117
+ test.beginning_with 'b'
118
+ test.word_size 4
119
+ test.word_count 2
120
+ puts test.to_s
121
+ test.print_letters
122
+ test.test_letters
123
+
73
124
  ```
74
125
 
75
126
  # Options:
data/cw.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'cw'
7
- spec.version = '0.0.12'
7
+ spec.version = '0.1.0'
8
8
  spec.date = '2016-05-21'
9
9
  spec.authors = ["Martyn Jago"]
10
10
  spec.email = ["martyn.jago@btinternet.com"]
data/daily.rb CHANGED
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  CW.new do
18
18
  shuffle
19
- wpm speed
19
+ wpm speed
20
20
  word_count 15
21
21
  test_letters
22
22
  end
@@ -90,7 +90,7 @@ speed -= 10
90
90
 
91
91
  CW.new do
92
92
  load_words 'data/text/cw_conversation.txt'
93
- wpm speed
93
+ wpm speed
94
94
  print_letters
95
95
  end
96
96
 
data/example.rb CHANGED
@@ -87,7 +87,6 @@ loop do
87
87
  test.word_count 4
88
88
  puts test.to_s
89
89
  test.test_words
90
- test = nil
91
90
 
92
91
  test = CW.new
93
92
  test.comment 'test words including ing'
@@ -98,7 +97,6 @@ loop do
98
97
  test.including 'ing'
99
98
  test.word_count 5
100
99
  test.test_words
101
- test = nil
102
100
 
103
101
  # test = CW.new
104
102
  # test.comment 'test ing'
@@ -15,7 +15,7 @@ class AudioPlayer
15
15
  end
16
16
 
17
17
  def convert_words_with_ebook2cw words
18
- words = words.gsub("\n","")
18
+ words = words.delete("\n")
19
19
  cl = Cl.new.cl_echo(words)
20
20
  ! @dry_run ? `#{cl}` : cl
21
21
  end
@@ -40,6 +40,8 @@ class AudioPlayer
40
40
  Process.kill(:TERM, @pid)
41
41
  Process.wait(@pid)
42
42
  rescue
43
+ puts 'Error: Failed to kill pid ' + @pid
44
+ exit 1
43
45
  end
44
46
  end
45
47
 
@@ -151,24 +151,32 @@ class Book < FileDetails
151
151
  end
152
152
  end
153
153
 
154
- def print_words words
155
- timing.init_char_timer
154
+ def process_letters letr
155
+ loop do
156
+ process_space_maybe(letr) unless @book_details.args[:output] == :letter
157
+ process_word_maybe
158
+ if change_repeat_or_quit?
159
+ break
160
+ end
161
+ break if timing.char_delay_timeout?
162
+ end
163
+ end
164
+
165
+ def process_words words
156
166
  (words + space).each_char do |letr|
157
167
  process_letter letr
158
168
  stream.add_char(letr) if @book_details.args[:output] == :letter
159
- loop do
160
- process_space_maybe(letr) unless @book_details.args[:output] == :letter
161
- process_word_maybe
162
- if change_repeat_or_quit?
163
- break
164
- end
165
- break if timing.char_delay_timeout?
166
- end
169
+ process_letters letr
167
170
  print.prn letr if print_letters?
168
171
  break if change_repeat_or_quit?
169
172
  end
170
173
  end
171
174
 
175
+ def print_words words
176
+ timing.init_char_timer
177
+ process_words words
178
+ end
179
+
172
180
  def print_words_for_current_sentence
173
181
  # puts current_sentence
174
182
  print_words current_sentence
@@ -185,7 +193,7 @@ class Book < FileDetails
185
193
  def play_sentences_until_quit
186
194
  get_book_progress
187
195
  loop do
188
- check_sentence_count :play
196
+ check_sentence_count
189
197
  sync_with_print
190
198
  audio_play_repeat_tone_maybe
191
199
  reset_sentence_flags
@@ -196,8 +204,8 @@ class Book < FileDetails
196
204
  print_words_exit unless @print_letters
197
205
  end
198
206
 
199
- def check_sentence_count source
200
- if @book_details.session_finished? source
207
+ def check_sentence_count
208
+ if @book_details.session_finished?
201
209
  audio_stop
202
210
  quit
203
211
  reset_stdin
@@ -207,7 +215,7 @@ class Book < FileDetails
207
215
 
208
216
  def print_sentences_until_quit
209
217
  loop do
210
- check_sentence_count :print
218
+ check_sentence_count
211
219
  sync_with_play
212
220
  break if quit?
213
221
  sync_with_audio_player
@@ -25,11 +25,11 @@ class BookDetails
25
25
  end
26
26
  end
27
27
 
28
- def session_finished? source
29
- sentences_complete?(source) || book_timeout?
28
+ def session_finished?
29
+ sentences_complete? || book_timeout?
30
30
  end
31
31
 
32
- def sentences_complete? source
32
+ def sentences_complete?
33
33
  if @args.has_key?(:sentences) && @args[:sentences].is_a?(Fixnum)
34
34
  if @sentence_count_source
35
35
  @sentence_count_source = nil
@@ -1,56 +1,72 @@
1
- # encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
- class CwEncoding
3
+ class CwEncoding
4
4
 
5
- def fetch char
6
- encode[char]
7
- end
5
+ def fetch char
6
+ encode(char)
7
+ end
8
+
9
+ def encode char
10
+ e = encode_a_n().merge!(encode_0_2);
11
+ (e.merge(encode_3_space))[char]
12
+ end
13
+
14
+ def encode_a_n
15
+ {
16
+ 'a' => [:dot, :dash],
17
+ 'b' => [:dash, :dot, :dot, :dot],
18
+ 'c' => [:dash, :dot, :dash, :dot],
19
+ 'd' => [:dash, :dot, :dot],
20
+ 'e' => [:dot],
21
+ 'f' => [:dot, :dot, :dash, :dot],
22
+ 'g' => [:dash, :dash, :dot],
23
+ 'h' => [:dot, :dot, :dot, :dot],
24
+ 'i' => [:dot, :dot],
25
+ 'j' => [:dot, :dash, :dash, :dash],
26
+ 'k' => [:dash, :dot, :dash],
27
+ 'l' => [:dot, :dash, :dot, :dot],
28
+ 'm' => [:dash, :dash],
29
+ 'n' => [:dash, :dot]
30
+ }
31
+ end
8
32
 
9
- def encode
33
+ def encode_0_2
10
34
  {
11
- 'a' => [:dot, :dash],
12
- 'b' => [:dash, :dot, :dot, :dot],
13
- 'c' => [:dash, :dot, :dash, :dot],
14
- 'd' => [:dash, :dot, :dot],
15
- 'e' => [:dot],
16
- 'f' => [:dot, :dot, :dash, :dot],
17
- 'g' => [:dash, :dash, :dot],
18
- 'h' => [:dot, :dot, :dot, :dot],
19
- 'i' => [:dot, :dot],
20
- 'j' => [:dot, :dash, :dash, :dash],
21
- 'k' => [:dash, :dot, :dash],
22
- 'l' => [:dot, :dash, :dot, :dot],
23
- 'm' => [:dash, :dash],
24
- 'n' => [:dash, :dot],
25
- 'o' => [:dash, :dash, :dash],
26
- 'p' => [:dot, :dash, :dash, :dot],
27
- 'q' => [:dash, :dash, :dot, :dash],
28
- 'r' => [:dot, :dash, :dot],
29
- 's' => [:dot, :dot, :dot],
30
- 't' => [:dash],
31
- 'u' => [:dot, :dot, :dash],
32
- 'v' => [:dot, :dot, :dot, :dash],
33
- 'w' => [:dot, :dash, :dash],
34
- 'x' => [:dash, :dot, :dot, :dash],
35
- 'y' => [:dash, :dot, :dash, :dash],
36
- 'z' => [:dash, :dash, :dot, :dot],
37
- '1' => [:dot, :dash, :dash, :dash, :dash],
38
- '2' => [:dot, :dot, :dash, :dash, :dash],
39
- '3' => [:dot, :dot, :dot, :dash, :dash],
40
- '4' => [:dot, :dot, :dot, :dot, :dash],
41
- '5' => [:dot, :dot, :dot, :dot, :dot],
42
- '6' => [:dash, :dot, :dot, :dot, :dot],
43
- '7' => [:dash, :dash, :dot, :dot, :dot],
44
- '8' => [:dash, :dash, :dash, :dot, :dot],
45
- '9' => [:dash, :dash, :dash, :dash, :dot],
46
- '0' => [:dash, :dash, :dash, :dash, :dash],
47
- '.' => [:dot, :dash, :dot, :dash, :dot, :dash],
48
- ',' => [:dash, :dash, :dot, :dot, :dash, :dash],
49
- '=' => [:dash, :dot, :dot,:dot, :dash],
50
- '!' => [:dot, :dot, :dash, :dash, :dot],
51
- '/' => [:dash, :dot, :dot, :dash, :dot],
52
- '?' => [:dot, :dot, :dash, :dash, :dot, :dot],
53
- ' ' => []
54
- }
35
+ 'o' => [:dash, :dash, :dash],
36
+ 'p' => [:dot, :dash, :dash, :dot],
37
+ 'q' => [:dash, :dash, :dot, :dash],
38
+ 'r' => [:dot, :dash, :dot],
39
+ 's' => [:dot, :dot, :dot],
40
+ 't' => [:dash],
41
+ 'u' => [:dot, :dot, :dash],
42
+ 'v' => [:dot, :dot, :dot, :dash],
43
+ 'w' => [:dot, :dash, :dash],
44
+ 'x' => [:dash, :dot, :dot, :dash],
45
+ 'y' => [:dash, :dot, :dash, :dash],
46
+ 'z' => [:dash, :dash, :dot, :dot],
47
+ '1' => [:dot, :dash, :dash, :dash, :dash],
48
+ '2' => [:dot, :dot, :dash, :dash, :dash]
49
+ }
50
+ end
51
+
52
+ def encode_3_space
53
+ {
54
+ '3' => [:dot, :dot, :dot, :dash, :dash],
55
+ '4' => [:dot, :dot, :dot, :dot, :dash],
56
+ '5' => [:dot, :dot, :dot, :dot, :dot],
57
+ '6' => [:dash, :dot, :dot, :dot, :dot],
58
+ '7' => [:dash, :dash, :dot, :dot, :dot],
59
+ '8' => [:dash, :dash, :dash, :dot, :dot],
60
+ '9' => [:dash, :dash, :dash, :dash, :dot],
61
+ '0' => [:dash, :dash, :dash, :dash, :dash],
62
+ '.' => [:dot, :dash, :dot, :dash, :dot, :dash],
63
+ ',' => [:dash, :dash, :dot, :dot, :dash, :dash],
64
+ '=' => [:dash, :dot, :dot,:dot, :dash],
65
+ '!' => [:dot, :dot, :dash, :dash, :dot],
66
+ '/' => [:dash, :dot, :dot, :dash, :dot],
67
+ '?' => [:dot, :dot, :dash, :dash, :dot, :dot],
68
+ ' ' => []
69
+ }
70
+ end
71
+
55
72
  end
56
- end
@@ -81,57 +81,62 @@ class Print
81
81
  end
82
82
  end
83
83
 
84
- def char_result popped
85
- if popped
86
- value = popped[:value]
87
- success = popped[:success]
84
+ def paint(value, colour)
85
+ Paint[value, colour]
86
+ end
88
87
 
89
- unless newline_maybe value
90
- #return if @print_count == 0 && value == ' '
91
- value = '_' if((value == ' ') && (success != true))
92
- print Paint["#{value}", :blue] if success
93
- print Paint["#{value}", :red ] unless success
94
- return true
95
- end
88
+ def paint_success_failure(popped)
89
+ print paint(popped[:value], :blue) if popped[:success]
90
+ print paint(popped[:value], :red ) unless popped[:success]
91
+ end
92
+
93
+ def char_result popped
94
+ unless newline_maybe popped[:value]
95
+ popped[:value] = '_' if((popped[:value] == ' ') && (popped[:success] != true))
96
+ paint_success_failure(popped)
97
+ return true
96
98
  end
97
99
  end
98
100
 
99
101
  def heading
100
- puts ("*" * "Current Sentence is duration: secs".length) + "\r"
102
+ "Current Sentence is duration: secs".length.times do
103
+ print '*'
104
+ puts
105
+ end
101
106
  end
102
107
 
103
108
  def print_blue(word)
104
- print Paint[word, :blue]
109
+ print paint(word, :blue)
105
110
  cursor_pos = word.size
106
111
  (12 - cursor_pos).times{print ' '}
107
112
  end
108
113
 
109
114
  def print_green(word)
110
115
  print_blue(word)
111
- print Paint["#{word} \r\n", :green]
116
+ print paint("#{word} \r\n", :green)
112
117
  end
113
118
 
114
119
  def print_red word
115
- print Paint["#{word }\r\n", :red]
120
+ print paint("#{word }\r\n", :red)
116
121
  end
117
122
 
118
123
  def prn_red word
119
- print Paint["#{word}", :red]
124
+ print paint("#{word}", :red)
120
125
  end
121
126
 
122
127
  def print_fail(word, attempt)
123
128
  print_blue(word)
124
- print Paint["#{attempt }\r\n", :red]
129
+ print paint("#{attempt }\r\n", :red)
125
130
  end
126
131
 
127
132
  def prn(word)
128
133
  newline_maybe word
129
134
  return if(@print_count == 0 && word == ' ')
130
- print Paint["#{word}", :blue]
135
+ print paint("#{word}", :blue)
131
136
  end
132
137
 
133
138
  def print_advice name
134
- puts "#{name.to_s}: Press Q 4 times to Exit"
139
+ puts "#{name}: Press Q 4 times to Exit"
135
140
  end
136
141
 
137
142
  end