cw 0.2.2 → 0.2.4

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: 09025bf62e23f145015ed647348560e166c13640
4
- data.tar.gz: 20c42fe062a63d93af07612f55de735082abdbc9
3
+ metadata.gz: 4e1587225798871292fb766303aa33e8aa488d72
4
+ data.tar.gz: 7d75a4190163a579f8cc88f9287e579c1657facd
5
5
  SHA512:
6
- metadata.gz: 08ed885767204c62256304b8da186936e1ff5d139c3e3e4e4e2779d28a3942f70b37886827970770c52fd4d29a0686d6617864fa06112937f2e706b4a1e2d19c
7
- data.tar.gz: 830654b291168f7e33174b2e34e3004b5a4f308557d871b4838d170bd793cac3ed71e68da54b7e84e36ad2544c26b7870f6cfdd8fcec1d31be975a2ac6aa7a1a
6
+ metadata.gz: 85ec2d8ab4291cae6fa85f3e02700a080e4bdba7e634378de4d445c656b0b39375805978a80ce4e93fa1388c128815d96d6a4fcfab0302b451766d57661e790d
7
+ data.tar.gz: 4e61d5b90e40004359ae53751555c3de33a135f02c333ce9d15fc842b0b227b09a77e84846b26841cc1bc4dff77c30f15aae1e1eb0639c130a9e799a9a9ad9cd
data/.gitignore CHANGED
@@ -8,7 +8,7 @@ Gemfile.lock
8
8
  *.gem
9
9
  *.rbc
10
10
  .bundle
11
- .config
11
+ .cw_config
12
12
  coverage
13
13
  InstalledFiles
14
14
  lib/bundler/man
@@ -18,13 +18,13 @@ spec/reports
18
18
  test/tmp
19
19
  test/version_tmp
20
20
  tmp
21
-
21
+ books/
22
22
  # YARD artifacts
23
23
  .yardoc
24
24
  _yardoc
25
25
  doc/
26
26
  /.ruby_version/
27
-
27
+ /data/text/progress.txt
28
28
  audio/audio_output.wav
29
29
  /audio/dash.wav
30
30
  /audio/audio_output.wav
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.9.3"
4
3
  - "2.0.0"
4
+ - "2.1.0"
5
5
  - "2.2.3"
6
6
  script:
7
7
  - rake test
data/README.md CHANGED
@@ -3,70 +3,67 @@
3
3
  [![Code Climate](https://codeclimate.com/github/mjago/CW/badges/gpa.svg)](https://codeclimate.com/github/mjago/CW)
4
4
  [![Dependency Status](https://gemnasium.com/badges/github.com/mjago/CW.svg)](https://gemnasium.com/github.com/mjago/CW)
5
5
 
6
+ # Documentation:
7
+
8
+ **[CW Documentation](http://mjago.github.io/CW/)**
9
+
6
10
  ## CW
7
11
 
8
- CW is a DSL written in the [Ruby](https://www.ruby-lang.org/en/downloads/) language for generating audible morse - allowing for
9
- 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.
12
+ **CW** is a program for learning and practicing Morse Code (CW). It is written in the form of a [DSL](https://en.wikipedia.org/wiki/Domain-specific_language/) in the [Ruby](https://www.ruby-lang.org/en/downloads/) language.
10
13
 
11
- CW can read books (and remember where you are), rss feeds (your daily quotation for instance), common phrases, QSO codes etc, in
12
- addition to generating random words, letters, and numbers that possibly match some required pattern
13
- (i.e. words_beginning_with 'v').
14
+ **CW** can read _books_ (and remember where you are), _rss feeds_ (your daily quotation for instance), common _phrases_, _QSO_ codes etc, in
15
+ addition to generating random words, letters, and numbers that possibly match some required pattern (i.e. words_beginning_with 'v').
14
16
 
15
- 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).
17
+ **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).
16
18
 
19
+ **CW** is thoroughly [documented](http://mjago.github.io/CW/), and includes a [hands-on tutorial](http://mjago.github.io/CW/mydoc_five_common_words/).
17
20
 
18
21
  # Installation:
19
22
 
20
23
  ```sh
21
-
22
24
  gem install cw
23
25
  ruby example.rb
24
-
25
26
  ```
26
27
 
27
28
  * Note: Currently only tested on OS X, and Ruby v1.9.3 and later.
28
29
 
29
- # Documentation:
30
-
31
- [CW Documentation](http://mjago.github.io/CW/)
32
-
33
30
  # Example test-script
34
31
 
35
32
  ```ruby
36
33
 
37
- # example.rb (example script)
34
+ # example.rb (example script)
38
35
 
39
36
  require 'cw'
40
37
 
41
- CW.new do
38
+ cw do
42
39
  wpm 18
43
40
  comment 'read book (1 sentence)'
44
41
  play_book(sentences: 1)
45
42
  end
46
43
 
47
- CW.new do
44
+ cw do
48
45
  wpm 18
49
46
  ewpm 12
50
47
  comment 'read book (2 minutes)'
51
48
  play_book(duration: 2)
52
49
  end
53
50
 
54
- CW.new do
51
+ cw do
55
52
  comment 'read rss feed (1 article)'
56
53
  read_rss(:reuters, 1)
57
54
  end
58
55
 
59
- CW.new do
56
+ cw do
60
57
  name 'test straight alphabet'
61
58
  alphabet
62
59
  end
63
60
 
64
- CW.new do
61
+ cw do
65
62
  comment 'test straight numbers'
66
63
  numbers
67
64
  end
68
65
 
69
- CW.new do
66
+ cw do
70
67
  wpm 18
71
68
  ewpm 12
72
69
  load_abbreviations
@@ -129,27 +126,6 @@ test.test_letters
129
126
 
130
127
  ```
131
128
 
132
- # Options:
133
-
134
- Command / Alias
135
- ---------------
136
- - ewpm / effective_wpm
137
- - no_run / pause
138
- - comment / name
139
- - repeat_word / double_words
140
- - word_length / word_size
141
- - word_shuffle / shuffle
142
- - random_letters
143
- - random_numbers
144
- - having_size_of / word_size
145
- - number_of_words / word_count
146
- - words_including / including
147
- - words_ending_with / ending_with
148
- - random_alphanumeric / random_letters_numbers
149
- - words_beginning_with / beginning_with
150
- - words_no_longer_than / no_longer_than
151
- - words_no_shorter_than / no_shorter_than
152
-
153
129
  # License
154
130
 
155
131
  [MIT License](https://raw.githubusercontent.com/mjago/CW/master/LICENSE)
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
+ require 'rake/version_task'
5
+ Rake::VersionTask.new
6
+
4
7
  Rake::TestTask.new do |t|
5
8
  t.pattern = "test/test_*.rb"
9
+ # t.pattern = "test/test_tester.rb"
6
10
  end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.4
data/bin/cw ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ iterate = nil
4
+ count = 1
5
+ def number_or_nil(string)
6
+ Integer(string || '')
7
+ rescue ArgumentError
8
+ nil
9
+ end
10
+
11
+ def iterate?
12
+ number_or_nil ARGV[ARGV.size - 1]
13
+ end
14
+
15
+ if iterate?
16
+ count = ARGV.pop.to_i
17
+ iterate = true
18
+ end
19
+
20
+ def check_file_exists? file
21
+ File.exists? file
22
+ end
23
+
24
+ def check_sans_extension file
25
+ File.exists?("#{file}.rb")
26
+ end
27
+
28
+ def get_filename file
29
+ return_val = nil
30
+ if check_file_exists?(file)
31
+ return_val = file
32
+ elsif check_sans_extension(file)
33
+ return_val = "#{file}.rb"
34
+ end
35
+ return_val
36
+ end
37
+
38
+ count.times do |iter|
39
+ print "Iteration: #{iter + 1} " if iterate
40
+ ARGV.each do |arg|
41
+ file = get_filename(arg)
42
+ system("ruby #{file}") if file
43
+ end
44
+ end
data/cw.gemspec CHANGED
@@ -4,19 +4,21 @@ $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.2.2'
7
+ spec.version = File.read('VERSION')
8
8
  spec.date = '2016-05-21'
9
9
  spec.authors = ["Martyn Jago"]
10
10
  spec.email = ["martyn.jago@btinternet.com"]
11
11
  spec.description = "A ruby library to help learn and practice morse code"
12
12
  spec.summary = "CW tutor / exerciser"
13
- spec.homepage = 'http://github.com/mjago/cw'
13
+ spec.homepage = 'http://martynjago.co.uk/CW/'
14
14
  spec.files = `git ls-files`.split($/)
15
+ spec.executables = "cw"
16
+ spec.bindir = 'bin'
15
17
  spec.license = 'MIT'
16
18
 
17
19
  spec.require_paths = ["lib", "audio", "data/text", "test"]
18
20
 
19
- spec.required_ruby_version = '>= 1.9.3'
21
+ spec.required_ruby_version = '>= 2.0.0'
20
22
  spec.add_runtime_dependency 'feedjira', '>= 2.0.0'
21
23
  spec.add_runtime_dependency 'htmlentities', '>= 4.3.4'
22
24
  spec.add_runtime_dependency 'paint', '>= 1.0.1'
@@ -25,6 +27,7 @@ Gem::Specification.new do |spec|
25
27
  spec.add_runtime_dependency 'sanitize', '>= 4.0.1'
26
28
  spec.add_runtime_dependency 'wavefile', '>= 0.7.0'
27
29
 
28
- spec.add_development_dependency "minitest"
29
- spec.add_development_dependency "simplecov"
30
+ spec.add_development_dependency 'version', '>= 1.0.0'
31
+ spec.add_development_dependency 'minitest', '>= 5.8.4'
32
+ spec.add_development_dependency 'simplecov', '>= 0.12.0'
30
33
  end
@@ -2185,8 +2185,8 @@ I smiled and shook my head. I can quite understand your thinking
2185
2185
  so. I said. Of course, in your position of unofficial adviser and
2186
2186
  helper to everybody who is absolutely puzzled, throughout three
2187
2187
  continents, you are brought in contact with all that is strange and
2188
- bizarre. But hereI picked up the morning paper from the
2189
- groundlet us put it to a practical test. Here is the first heading
2188
+ bizarre. But here I picked up the morning paper from the
2189
+ ground let us put it to a practical test. Here is the first heading
2190
2190
  upon which I come. A husbands cruelty to his wife. There is half a
2191
2191
  column of print, but I know without reading it that it is all
2192
2192
  perfectly familiar to me. There is, of course, the other woman, the
@@ -9033,7 +9033,7 @@ inquiry on hand and that you disliked the intrusion of other
9033
9033
  matters.
9034
9034
 
9035
9035
  Oh, you mean the little problem of the Grosvenor Square furniture
9036
- van. That is quite cleared up nowthough, indeed, it was obvious
9036
+ van. That is quite cleared up now though, indeed, it was obvious
9037
9037
  from the first. Pray give me the results of your newspaper
9038
9038
  selections.
9039
9039
 
@@ -9081,7 +9081,7 @@ say that the marriage would be an absolutely quiet one, that it would
9081
9081
  be at St. Georges, Hanover Square, that only half a dozen intimate
9082
9082
  friends would be invited, and that the party would return to the
9083
9083
  furnished house at Lancaster Gate which has been taken by Mr.
9084
- Aloysius Doran. Two days laterthat is, on Wednesday lastthere is
9084
+ Aloysius Doran. Two days later that is, on Wednesday lastthere is
9085
9085
  a curt announcement that the wedding had taken place, and that the
9086
9086
  honeymoon would be passed at Lord Backwaters place, near
9087
9087
  Petersfield. Those are all the notices which appeared before the
data/example.rb CHANGED
@@ -1,38 +1,38 @@
1
1
  require 'cw'
2
2
 
3
- CW.new do
3
+ cw do
4
4
  comment 'read book feed (1 sentence)'
5
- play_book(sentences: 1)
5
+ read_book(sentences: 1)
6
6
  end
7
7
 
8
- CW.new do
8
+ cw do
9
9
  comment 'read book feed (1 minute)'
10
- play_book(duration: 1)
10
+ read_book(duration: 1)
11
11
  end
12
12
 
13
- CW.new do
13
+ cw do
14
14
  comment 'read rss feed (1 article)'
15
15
  read_rss(:reuters, 1)
16
16
  end
17
17
 
18
- CW.new do
18
+ cw do
19
19
  name 'test straight alphabet'
20
20
  alphabet
21
21
  end
22
22
 
23
- CW.new do
23
+ cw do
24
24
  comment 'test straight numbers'
25
25
  numbers
26
26
  end
27
27
 
28
- CW.new do
28
+ cw do
29
29
  wpm 18
30
30
  ewpm 12
31
31
  load_abbreviations
32
32
  shuffle
33
33
  end
34
34
 
35
- CW.new do
35
+ cw do
36
36
  wpm 18
37
37
  ewpm 12
38
38
  load_q_codes
@@ -52,20 +52,20 @@ def cw_settings
52
52
  puts self.to_s
53
53
  end
54
54
 
55
- CW.new do
55
+ cw do
56
56
  comment 'test random letters'
57
57
  random_letters(size: 4)
58
58
  cw_settings
59
59
  end
60
60
 
61
- CW.new do
61
+ cw do
62
62
  comment 'test random numbers'
63
63
  # use_ebook2cw
64
64
  cw_settings
65
65
  random_numbers(count: 2, size: 5)
66
66
  end
67
67
 
68
- CW.new do
68
+ cw do
69
69
  comment 'test random letters numbers'
70
70
  # use_ebook2cw
71
71
  cw_settings
@@ -76,7 +76,7 @@ wpm = 15
76
76
  ewpm = 12
77
77
  loop do
78
78
 
79
- test = CW.new
79
+ test = cw
80
80
  # test.use_ebook2cw
81
81
  test.comment 'test words beginning with b'
82
82
  test.shuffle
@@ -88,7 +88,7 @@ loop do
88
88
  puts test.to_s
89
89
  test.test_words
90
90
 
91
- test = CW.new
91
+ test = cw
92
92
  test.comment 'test words including ing'
93
93
  # test.use_ebook2cw
94
94
  test.shuffle
@@ -98,7 +98,7 @@ loop do
98
98
  test.word_count 5
99
99
  test.test_words
100
100
 
101
- # test = CW.new
101
+ # test = cw
102
102
  # test.comment 'test ing'
103
103
  # test.use_ebook2cw
104
104
  ## test.shuffle
@@ -109,7 +109,7 @@ loop do
109
109
  # test.word_count 5
110
110
  # test.test_words
111
111
  #
112
- # test = CW.new
112
+ # test = cw
113
113
  # test.comment 'test ing'
114
114
  # test.use_ruby_tone
115
115
  ## test.shuffle
@@ -120,7 +120,7 @@ loop do
120
120
  # test.word_count 5
121
121
  # test.test_words
122
122
 
123
- # test = CW.new
123
+ # test = cw
124
124
  # test.comment 'test ing'
125
125
  # test.shuffle
126
126
  # test.wpm wpm
data/lib/cw.rb CHANGED
@@ -15,7 +15,7 @@ require_relative 'cw/str'
15
15
  require_relative 'cw/rss'
16
16
  require_relative 'cw/words'
17
17
  require_relative 'cw/cl'
18
- require_relative 'cw/cw_params'
18
+ require_relative 'cw/params'
19
19
  require_relative 'cw/key_input'
20
20
  require_relative 'cw/cw_stream'
21
21
  require_relative 'cw/timing'
@@ -27,23 +27,43 @@ require_relative 'cw/tester'
27
27
  require_relative 'cw/test_words'
28
28
  require_relative 'cw/test_letters'
29
29
  require_relative 'cw/repeat_word'
30
+ require_relative 'cw/reveal'
30
31
  require_relative 'cw/book'
31
32
  require_relative 'cw/cw_encoding'
32
- require_relative 'cw/tone_generator.rb'
33
+ require_relative 'cw/tone_generator'
33
34
  require_relative 'cw/progress'
35
+ require_relative 'cw/config_file'
34
36
 
35
37
  # CW provides Morse code generation functionality
36
38
 
39
+ def cw &block
40
+ CW.new do
41
+ instance_eval &block
42
+ end
43
+ end
44
+
37
45
  class CW < CwDsl
38
46
 
39
47
  #FIXME dry_run
40
48
  # attr_accessor :dry_run
41
49
 
50
+ # Initialize CW class. Eval block if passed in.
51
+
52
+ def initialize(&block)
53
+
54
+ super
55
+
56
+ load_common_words# unless @words.exist?
57
+ ConfigFile.new.apply_config self
58
+ instance_eval(&block) if block
59
+ run if block
60
+ end
61
+
42
62
  # Test user against letters rather than words.
43
63
  #
44
64
 
45
65
  def test_letters
46
- @inhibit_block_run = true
66
+ Params.pause = true
47
67
  test_letters = TestLetters.new
48
68
  test_letters.run @words
49
69
  end
@@ -52,6 +72,7 @@ class CW < CwDsl
52
72
  #
53
73
 
54
74
  def test_words
75
+ Params.pause = true
55
76
  tw = TestWords.new
56
77
  tw.run @words
57
78
  end
@@ -60,21 +81,18 @@ class CW < CwDsl
60
81
  #
61
82
 
62
83
  def repeat_word
63
- @inhibit_block_run = true
84
+ Params.pause = true
64
85
  repeat_word = RepeatWord.new
65
86
  repeat_word.run @words
66
87
  end
67
88
 
68
- # Initialize CW class. Eval block if passed in.
69
-
89
+ # Reveal words only at end of test.
90
+ # Useful for learning to copy `in the head'
70
91
 
71
- def initialize(&block)
72
-
73
- super
74
-
75
- load_common_words# unless @words.exist?
76
- instance_eval(&block) if block
77
- run unless Params.pause if (block && ! @inhibit_block_run)
92
+ def reveal
93
+ Params.pause = true
94
+ reveal = Reveal.new
95
+ reveal.run @words
78
96
  end
79
97
 
80
98
  # Return string containing name or comment of test.
@@ -84,20 +102,35 @@ class CW < CwDsl
84
102
  @str.to_s
85
103
  end
86
104
 
105
+ def list
106
+ Print.new.list self.to_s
107
+ puts
108
+ end
109
+
87
110
  # Play book using provided arguments.
88
111
  # @param [Hash] args the options to play book with.
89
112
  # @option args [Integer] :sentences Number of sentences to play
90
113
  # @option args [Integer] :duration Number of minutes to play
91
114
  # @option args [Boolean] :letter Mark by letter if true else mark by word
92
115
 
93
- def play_book args = {}
94
- @inhibit_block_run = true
116
+ def read_book args = {}
117
+ Params.pause = true
95
118
  details = BookDetails.new
96
119
  details.arguments(args)
97
120
  book = Book.new details
98
121
  book.run @words
99
122
  end
100
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
+
101
134
  # Reads RSS feed (requires an internet connection). Feed can be one of:
102
135
  # - bbc:
103
136
  # - reuters:
@@ -107,7 +140,7 @@ class CW < CwDsl
107
140
  # @param [Integer] article_count Number of articles to play.
108
141
 
109
142
  def read_rss(source, article_count = 3)
110
- @inhibit_block_run = true
143
+ Params.pause = true
111
144
  rss, = Rss.new
112
145
  rss.read_rss(source, article_count)
113
146
  loop do
@@ -119,12 +152,14 @@ class CW < CwDsl
119
152
  end
120
153
 
121
154
  # Run word test
122
- def run ; test_words ; end
155
+ def run
156
+ return if Params.pause
157
+ test_words
158
+ end
123
159
 
124
160
  alias_method :ewpm, :effective_wpm
125
161
  alias_method :no_run, :pause
126
162
  alias_method :comment, :name
127
- # alias_method :repeat_word, :double_words
128
163
  alias_method :word_length, :word_size
129
164
  alias_method :word_shuffle, :shuffle
130
165
  alias_method :having_size_of, :word_size