cw 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +3 -0
- data/.travis.yml +3 -2
- data/README.md +6 -8
- data/Rakefile +5 -0
- data/classes.svg +145 -0
- data/classes.svg.dot +360 -0
- data/cw.gemspec +10 -9
- data/lib/cw.rb +6 -2
- data/lib/cw/audio_player.rb +2 -0
- data/lib/cw/book.rb +0 -27
- data/lib/cw/book_details.rb +27 -5
- data/lib/cw/current_word.rb +37 -0
- data/lib/cw/cw_dsl.rb +8 -7
- data/lib/cw/cw_params.rb +21 -0
- data/lib/cw/cw_stream.rb +3 -69
- data/lib/cw/element.rb +73 -0
- data/lib/cw/key_input.rb +1 -1
- data/lib/cw/repeat_word.rb +1 -0
- data/lib/cw/rss.rb +5 -15
- data/lib/cw/str.rb +9 -35
- data/lib/cw/tester.rb +33 -8
- data/lib/cw/text_helpers.rb +25 -0
- data/lib/cw/tone_generator.rb +1 -26
- data/lib/cw/tone_helpers.rb +33 -0
- data/lib/cw/words.rb +2 -54
- data/test/test_cw.rb +18 -11
- data/test/test_stream.rb +157 -151
- metadata +57 -52
- data/test/run_tests_continuously.rb +0 -4
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.2.
|
7
|
+
spec.version = '0.2.2'
|
8
8
|
spec.date = '2016-05-21'
|
9
9
|
spec.authors = ["Martyn Jago"]
|
10
10
|
spec.email = ["martyn.jago@btinternet.com"]
|
@@ -13,16 +13,17 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = 'http://github.com/mjago/cw'
|
14
14
|
spec.files = `git ls-files`.split($/)
|
15
15
|
spec.license = 'MIT'
|
16
|
+
|
16
17
|
spec.require_paths = ["lib", "audio", "data/text", "test"]
|
17
|
-
spec.required_ruby_version = '>= 2.0.0'
|
18
18
|
|
19
|
-
spec.
|
20
|
-
spec.
|
21
|
-
spec.
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
-
spec.
|
25
|
-
spec.
|
19
|
+
spec.required_ruby_version = '>= 1.9.3'
|
20
|
+
spec.add_runtime_dependency 'feedjira', '>= 2.0.0'
|
21
|
+
spec.add_runtime_dependency 'htmlentities', '>= 4.3.4'
|
22
|
+
spec.add_runtime_dependency 'paint', '>= 1.0.1'
|
23
|
+
spec.add_runtime_dependency 'rake', '>= 11.2.2'
|
24
|
+
spec.add_runtime_dependency 'ruby-progressbar', '>= 1.8.1'
|
25
|
+
spec.add_runtime_dependency 'sanitize', '>= 4.0.1'
|
26
|
+
spec.add_runtime_dependency 'wavefile', '>= 0.7.0'
|
26
27
|
|
27
28
|
spec.add_development_dependency "minitest"
|
28
29
|
spec.add_development_dependency "simplecov"
|
data/lib/cw.rb
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
require_relative 'cw/file_details'
|
4
4
|
require_relative 'cw/process'
|
5
|
+
require_relative 'cw/text_helpers'
|
6
|
+
require_relative 'cw/tone_helpers'
|
7
|
+
require_relative 'cw/element'
|
8
|
+
require_relative 'cw/current_word'
|
5
9
|
require_relative 'cw/cw_dsl'
|
6
10
|
require_relative 'cw/randomize'
|
7
11
|
require_relative 'cw/sentence'
|
@@ -32,8 +36,8 @@ require_relative 'cw/progress'
|
|
32
36
|
|
33
37
|
class CW < CwDsl
|
34
38
|
|
35
|
-
|
36
|
-
attr_accessor :
|
39
|
+
#FIXME dry_run
|
40
|
+
# attr_accessor :dry_run
|
37
41
|
|
38
42
|
# Test user against letters rather than words.
|
39
43
|
#
|
data/lib/cw/audio_player.rb
CHANGED
@@ -14,6 +14,7 @@ class AudioPlayer
|
|
14
14
|
@play_filename ||= "#{Params.audio_dir}/#{Params.audio_filename}0000.mp3"
|
15
15
|
end
|
16
16
|
|
17
|
+
#FIXME dry_run
|
17
18
|
def convert_words_with_ebook2cw words
|
18
19
|
words = words.delete("\n")
|
19
20
|
cl = Cl.new.cl_echo(words)
|
@@ -30,6 +31,7 @@ class AudioPlayer
|
|
30
31
|
tone.play_filename
|
31
32
|
end
|
32
33
|
|
34
|
+
#FIXME dry_run
|
33
35
|
def play
|
34
36
|
cmd = play_command + ' ' + play_filename
|
35
37
|
@pid = ! @dry_run ? Process.spawn(cmd) : cmd
|
data/lib/cw/book.rb
CHANGED
@@ -151,34 +151,7 @@ class Book < FileDetails
|
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
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
|
166
|
-
(words + space).each_char do |letr|
|
167
|
-
process_letter letr
|
168
|
-
stream.add_char(letr) if @book_details.args[:output] == :letter
|
169
|
-
process_letters letr
|
170
|
-
print.prn letr if print_letters?
|
171
|
-
break if change_repeat_or_quit?
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def print_words words
|
176
|
-
timing.init_char_timer
|
177
|
-
process_words words
|
178
|
-
end
|
179
|
-
|
180
154
|
def print_words_for_current_sentence
|
181
|
-
# puts current_sentence
|
182
155
|
print_words current_sentence
|
183
156
|
end
|
184
157
|
|
data/lib/cw/book_details.rb
CHANGED
@@ -5,16 +5,38 @@ class BookDetails
|
|
5
5
|
attr_reader :args
|
6
6
|
|
7
7
|
HERE = File.dirname(__FILE__) + '/'
|
8
|
-
|
9
|
-
|
8
|
+
GEM_BOOK_DIRECTORY = HERE + '../../data/text/'
|
9
|
+
GEM_BOOK_NAME = 'adv_of_sh_holmes.txt'
|
10
|
+
DEFAULT_BOOK_DIRECTORY = 'books'
|
10
11
|
|
11
12
|
def initialize
|
12
|
-
|
13
|
-
|
13
|
+
book_directory
|
14
|
+
book_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_default_book_dir?
|
18
|
+
if File.exist? DEFAULT_BOOK_DIRECTORY
|
19
|
+
if File.directory? DEFAULT_BOOK_DIRECTORY
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def book_name
|
27
|
+
Params.book_name ||= GEM_BOOK_NAME
|
28
|
+
end
|
29
|
+
|
30
|
+
def book_directory
|
31
|
+
book_dir = GEM_BOOK_DIRECTORY
|
32
|
+
if is_default_book_dir?
|
33
|
+
book_dir = DEFAULT_BOOK_DIRECTORY
|
34
|
+
end
|
35
|
+
Params.book_dir ||= book_dir
|
14
36
|
end
|
15
37
|
|
16
38
|
def book_location
|
17
|
-
|
39
|
+
File.expand_path(File.join Params.book_dir, Params.book_name)
|
18
40
|
end
|
19
41
|
|
20
42
|
def arguments args
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class CurrentWord
|
4
|
+
|
5
|
+
include TextHelpers
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@current_word = ''
|
9
|
+
end
|
10
|
+
|
11
|
+
def current_word
|
12
|
+
@current_word ||= String.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def push_letter letr
|
16
|
+
@current_word += letr
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
@current_word
|
21
|
+
end
|
22
|
+
|
23
|
+
def clear
|
24
|
+
@current_word.clear
|
25
|
+
@current_word = ''
|
26
|
+
end
|
27
|
+
|
28
|
+
def strip
|
29
|
+
@current_word.strip!
|
30
|
+
end
|
31
|
+
|
32
|
+
def process_letter letr
|
33
|
+
letr.downcase!
|
34
|
+
push_letter letr
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/cw/cw_dsl.rb
CHANGED
@@ -27,7 +27,8 @@ class CwDsl
|
|
27
27
|
:pause, :noise,
|
28
28
|
:shuffle, :mark_words,
|
29
29
|
:double_words, :single_words,
|
30
|
-
:audio_dir, :def_word_count
|
30
|
+
:audio_dir, :def_word_count,
|
31
|
+
:book_name, :book_dir
|
31
32
|
].each do |method|
|
32
33
|
define_method method do |arg = nil|
|
33
34
|
arg ? Params.send("#{method}=", arg) : Params.send("#{method}")
|
@@ -61,7 +62,7 @@ class CwDsl
|
|
61
62
|
:word_filename, :author, :title, :quality, :frequency, :shuffle, :effective_wpm,
|
62
63
|
:max, :min, :word_spacing, :noise, :begin, :end, :word_count, :including,
|
63
64
|
:word_size, :size, :beginning_with, :ending_with, :mark_words, :audio_dir,
|
64
|
-
:use_ebook2cw, :def_word_count
|
65
|
+
:use_ebook2cw, :def_word_count, :book_dir, :book_name
|
65
66
|
end
|
66
67
|
|
67
68
|
config_defaults
|
@@ -102,6 +103,11 @@ class CwDsl
|
|
102
103
|
Params.size
|
103
104
|
end
|
104
105
|
|
106
|
+
def word_count(wordcount)
|
107
|
+
Params.word_count = wordcount
|
108
|
+
@words.count wordcount
|
109
|
+
end
|
110
|
+
|
105
111
|
def beginning_with(* letters)
|
106
112
|
@words.beginning_with letters
|
107
113
|
Params.begin = letters
|
@@ -112,11 +118,6 @@ class CwDsl
|
|
112
118
|
Params.end = letters
|
113
119
|
end
|
114
120
|
|
115
|
-
def word_count(wordcount)
|
116
|
-
Params.word_count = wordcount
|
117
|
-
@words.count wordcount
|
118
|
-
end
|
119
|
-
|
120
121
|
def including(* letters)
|
121
122
|
Params.including = letters
|
122
123
|
@words.including letters
|
data/lib/cw/cw_params.rb
CHANGED
@@ -26,4 +26,25 @@ module Params
|
|
26
26
|
def config( & block)
|
27
27
|
instance_eval( & block)
|
28
28
|
end
|
29
|
+
|
30
|
+
def shuffle_str
|
31
|
+
shuffle ? "Shuffle: #{shuffle ? 'yes' : 'no'}\n" : nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def word_count_str
|
35
|
+
word_count ? "Word count: #{word_count}\n" : nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def wpm_str
|
39
|
+
"WPM: #{wpm}\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
def word_size_str
|
43
|
+
size ? "Word size: #{size}\n" : nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def delim_str
|
47
|
+
"#{'=' * Params.name.size}\n"
|
48
|
+
end
|
49
|
+
|
29
50
|
end
|
data/lib/cw/cw_stream.rb
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
3
|
class CwStream
|
4
4
|
|
5
|
+
include Element
|
6
|
+
|
5
7
|
attr_accessor :active_region
|
8
|
+
attr_accessor :stream
|
6
9
|
|
7
10
|
def initialize
|
8
11
|
@active_region = 6
|
@@ -13,10 +16,6 @@ class CwStream
|
|
13
16
|
@stream, @success, @first_element, @last_element = {},{}, 0, 0
|
14
17
|
end
|
15
18
|
|
16
|
-
def count
|
17
|
-
@last_element - @first_element
|
18
|
-
end
|
19
|
-
|
20
19
|
def add_word word
|
21
20
|
@stream[@last_element] = word.strip
|
22
21
|
@success[@last_element] = nil
|
@@ -29,14 +28,6 @@ class CwStream
|
|
29
28
|
inc_last_element
|
30
29
|
end
|
31
30
|
|
32
|
-
def inc_last_element
|
33
|
-
@last_element += 1
|
34
|
-
end
|
35
|
-
|
36
|
-
def inc_first_element
|
37
|
-
@first_element += 1
|
38
|
-
end
|
39
|
-
|
40
31
|
def mark(element, type)
|
41
32
|
@success[element] = type
|
42
33
|
end
|
@@ -113,61 +104,4 @@ class CwStream
|
|
113
104
|
end
|
114
105
|
end
|
115
106
|
|
116
|
-
def element type
|
117
|
-
return @last_element - 1 if type == :last
|
118
|
-
first = @last_element - @active_region - 1
|
119
|
-
first < 0 ? 0 : first
|
120
|
-
end
|
121
|
-
|
122
|
-
def match_first_active_element match
|
123
|
-
if ! stream_empty?
|
124
|
-
found = false
|
125
|
-
first = element(:first)
|
126
|
-
first.upto element(:last) do |ele|
|
127
|
-
if found
|
128
|
-
first.upto found - 1 do |failed|
|
129
|
-
@success[failed] = false # unless @success[ele]
|
130
|
-
end
|
131
|
-
break
|
132
|
-
elsif((@stream[ele] == match) && (! @success[ele]))
|
133
|
-
@success[ele], found = true, ele
|
134
|
-
else
|
135
|
-
@success[first] = false
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def match_last_active_element(match)
|
142
|
-
process_last_active_element(match) unless stream_empty?
|
143
|
-
end
|
144
|
-
|
145
|
-
def process_last_active_element(match)
|
146
|
-
first = get_first
|
147
|
-
last = get_last
|
148
|
-
check_last_element_success(match, first, last)
|
149
|
-
end
|
150
|
-
|
151
|
-
def check_last_element_success(match, first, last)
|
152
|
-
found = false
|
153
|
-
last.downto(first) do |element|
|
154
|
-
if found
|
155
|
-
@success[element] = false unless @success[element]
|
156
|
-
elsif((@stream[element] == match) && (! @success[element]))
|
157
|
-
@success[element], found = true, true
|
158
|
-
else
|
159
|
-
@success[first] = false
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def get_first
|
165
|
-
first = @last_element - @active_region - 1
|
166
|
-
first = 0 if(first < 0)
|
167
|
-
first
|
168
|
-
end
|
169
|
-
|
170
|
-
def get_last
|
171
|
-
@last_element - 1
|
172
|
-
end
|
173
107
|
end
|
data/lib/cw/element.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
module Element
|
2
|
+
|
3
|
+
def element type
|
4
|
+
return @last_element - 1 if type == :last
|
5
|
+
first = @last_element - @active_region - 1
|
6
|
+
first < 0 ? 0 : first
|
7
|
+
end
|
8
|
+
|
9
|
+
def match_first_active_element match
|
10
|
+
if ! stream_empty?
|
11
|
+
found = false
|
12
|
+
first = element(:first)
|
13
|
+
first.upto element(:last) do |ele|
|
14
|
+
if found
|
15
|
+
first.upto found - 1 do |failed|
|
16
|
+
@success[failed] = false # unless @success[ele]
|
17
|
+
end
|
18
|
+
break
|
19
|
+
elsif((@stream[ele] == match) && (! @success[ele]))
|
20
|
+
@success[ele], found = true, ele
|
21
|
+
else
|
22
|
+
@success[first] = false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def match_last_active_element(match)
|
29
|
+
process_last_active_element(match) unless stream_empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
def process_last_active_element(match)
|
33
|
+
first = get_first
|
34
|
+
last = get_last
|
35
|
+
check_last_element_success(match, first, last)
|
36
|
+
end
|
37
|
+
|
38
|
+
def check_last_element_success(match, first, last)
|
39
|
+
found = false
|
40
|
+
last.downto(first) do |element|
|
41
|
+
if found
|
42
|
+
@success[element] = false unless @success[element]
|
43
|
+
elsif((@stream[element] == match) && (! @success[element]))
|
44
|
+
@success[element], found = true, true
|
45
|
+
else
|
46
|
+
@success[first] = false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_first
|
52
|
+
first = @last_element - @active_region - 1
|
53
|
+
first = 0 if(first < 0)
|
54
|
+
first
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_last
|
58
|
+
@last_element - 1
|
59
|
+
end
|
60
|
+
|
61
|
+
def count
|
62
|
+
@last_element - @first_element
|
63
|
+
end
|
64
|
+
|
65
|
+
def inc_last_element
|
66
|
+
@last_element += 1
|
67
|
+
end
|
68
|
+
|
69
|
+
def inc_first_element
|
70
|
+
@first_element += 1
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/lib/cw/key_input.rb
CHANGED