cw 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cw_config +18 -0
- data/.gitignore +10 -1
- data/LICENSE +2 -1
- data/README.md +212 -96
- data/Rakefile +15 -2
- data/VERSION +1 -1
- data/Vagrantfile +45 -0
- data/cw.gemspec +6 -1
- data/data/text/book_to_read.txt +4 -0
- data/data/text/english.txt +10000 -0
- data/example.rb +172 -106
- data/lib/cw.rb +10 -126
- data/lib/cw/alphabet.rb +53 -46
- data/lib/cw/audio_player.rb +83 -72
- data/lib/cw/book.rb +160 -185
- data/lib/cw/book_details.rb +38 -49
- data/lib/cw/cl.rb +101 -95
- data/lib/cw/common_words.rb +76 -0
- data/lib/cw/config.rb +50 -0
- data/lib/cw/current_word.rb +23 -24
- data/lib/cw/cw_dsl.rb +264 -131
- data/lib/cw/cw_encoding.rb +63 -69
- data/lib/cw/cw_stream.rb +86 -82
- data/lib/cw/cw_threads.rb +132 -22
- data/lib/cw/element.rb +60 -54
- data/lib/cw/file_details.rb +26 -11
- data/lib/cw/key_input.rb +53 -35
- data/lib/cw/numbers.rb +26 -19
- data/lib/cw/os.rb +13 -0
- data/lib/cw/play.rb +92 -0
- data/lib/cw/print.rb +102 -100
- data/lib/cw/process.rb +3 -0
- data/lib/cw/progress.rb +20 -17
- data/lib/cw/randomize.rb +56 -52
- data/lib/cw/repeat_word.rb +59 -66
- data/lib/cw/reveal.rb +32 -31
- data/lib/cw/rss.rb +52 -48
- data/lib/cw/sentence.rb +83 -76
- data/lib/cw/speak.rb +8 -4
- data/lib/cw/spoken.rb +8 -4
- data/lib/cw/str.rb +62 -30
- data/lib/cw/test_letters.rb +20 -28
- data/lib/cw/test_words.rb +25 -31
- data/lib/cw/tester.rb +219 -226
- data/lib/cw/text_helpers.rb +19 -15
- data/lib/cw/timing.rb +63 -67
- data/lib/cw/tone_generator.rb +176 -153
- data/lib/cw/tone_helpers.rb +15 -23
- data/lib/cw/voice.rb +12 -8
- data/lib/cw/words.rb +136 -106
- data/run_script_tests.rb +165 -0
- data/test/my_words.txt +1 -0
- data/test/test_common_words.rb +71 -0
- data/test/test_config.rb +98 -0
- data/test/test_current_word.rb +62 -0
- data/test/test_cw.rb +87 -120
- data/test/test_cw_threads.rb +123 -0
- data/test/test_filtering.rb +439 -0
- data/test/test_params.rb +28 -0
- data/test/test_play.rb +51 -0
- data/test/test_stream.rb +83 -83
- data/test/test_tester.rb +9 -27
- data/test/test_timing.rb +212 -0
- metadata +94 -12
- data/lib/cw/config_file.rb +0 -69
- data/lib/cw/monitor_keys.rb +0 -37
- data/lib/cw/params.rb +0 -104
data/lib/cw/sentence.rb
CHANGED
@@ -1,98 +1,105 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
3
|
+
module CWG
|
4
|
+
|
5
|
+
class Sentence
|
6
|
+
|
7
|
+
attr_accessor :index #todo
|
8
|
+
|
9
|
+
def text ; @text ||= String.new ; end
|
10
|
+
def all ; @sentences ; end
|
11
|
+
def next ; @next = true ; end
|
12
|
+
def next? ; @next ; end
|
13
|
+
#todo def forward ; @index += 1 ; end
|
14
|
+
def forward ; @index ; end
|
15
|
+
def previous? ; @previous ; end
|
16
|
+
def repeat? ; @repeat ; end
|
17
|
+
def change? ; next? || previous? ; end
|
18
|
+
def change_or_repeat? ; change? || repeat? ; end
|
19
|
+
def current ; @sentences[@index] ; end
|
20
|
+
def next_sentence ; @sentences[@index + 1] ; end
|
21
|
+
|
22
|
+
def change
|
23
|
+
forward if next?
|
24
|
+
rewind if previous?
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
def rewind
|
28
|
+
@index = @index <= 1 ? 0 : @index - 1
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
def create_progress_maybe progress_file
|
32
|
+
unless File.exists? progress_file
|
33
|
+
reset_progress progress_file
|
34
|
+
end
|
32
35
|
end
|
33
|
-
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def reset_progress progress_file
|
38
|
+
@index = 0
|
39
|
+
write_progress progress_file
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
def check_end_of_book progress_file
|
43
|
+
if @index >= @sentences.size
|
44
|
+
reset_progress progress_file
|
45
|
+
end
|
43
46
|
end
|
44
|
-
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
def read_progress progress_file
|
49
|
+
create_progress_maybe progress_file
|
50
|
+
File.open(progress_file, 'r') {|f| @index = f.readline.to_i}
|
51
|
+
unless(@index && @index.class == Fixnum)
|
52
|
+
reset_progress progress_file
|
53
|
+
end
|
54
|
+
check_end_of_book progress_file
|
55
|
+
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
57
|
+
def write_progress progress_file
|
58
|
+
File.open(progress_file, 'w') {|f| f.puts @index.to_s}
|
59
|
+
end
|
55
60
|
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
def read_book book
|
62
|
+
File.open(book, 'r') { |f| text.replace f.readlines(' ').join}
|
63
|
+
end
|
59
64
|
|
60
|
-
|
61
|
-
|
62
|
-
|
65
|
+
def cw_chars chr
|
66
|
+
chr.tr('^a-z0-9\,\=\!\/\?\.', '')
|
67
|
+
end
|
63
68
|
|
64
|
-
|
65
|
-
|
66
|
-
|
69
|
+
def exclude_non_cw_chars word
|
70
|
+
cw_chars(word)
|
71
|
+
end
|
67
72
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
def find_all
|
74
|
+
@sentences = []
|
75
|
+
@text.gsub!(/\s+/, ' ').downcase!
|
76
|
+
loop do
|
77
|
+
sentence_end = @text.index('. ')
|
78
|
+
unless sentence_end
|
79
|
+
break
|
80
|
+
end
|
81
|
+
line = @text[0..sentence_end]
|
82
|
+
line = line.split.collect{|word| exclude_non_cw_chars word}.join(' ')
|
83
|
+
@sentences << line
|
84
|
+
@text.replace @text[sentence_end + 2..-1]
|
75
85
|
end
|
76
|
-
line = @text[0..sentence_end]
|
77
|
-
line = line.split.collect{|word| exclude_non_cw_chars word}.join(' ')
|
78
|
-
@sentences << line
|
79
|
-
@text.replace @text[sentence_end + 2..-1]
|
80
86
|
end
|
81
|
-
end
|
82
87
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
+
def check_sentence_navigation chr
|
89
|
+
@next = true if(chr == ']')
|
90
|
+
@previous = true if(chr == '[')
|
91
|
+
@repeat = true if(chr == '-')
|
92
|
+
end
|
88
93
|
|
89
|
-
|
90
|
-
|
91
|
-
|
94
|
+
def reset_flags
|
95
|
+
@next = @previous = @repeat = nil
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_array
|
99
|
+
array = @sentences[@index].split(' ')
|
100
|
+
array.collect {|x| x + ' '}
|
101
|
+
end
|
92
102
|
|
93
|
-
def to_array
|
94
|
-
array = @sentences[@index].split(' ')
|
95
|
-
array.collect {|x| x + ' '}
|
96
103
|
end
|
97
104
|
|
98
105
|
end
|
data/lib/cw/speak.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
class
|
5
|
+
#class Numbers provides the Number Testing functionality
|
6
|
+
|
7
|
+
class Spoken
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
@options = options
|
11
|
+
end
|
6
12
|
|
7
|
-
def initialize(options = {})
|
8
|
-
@options = options
|
9
13
|
end
|
10
14
|
|
11
15
|
end
|
data/lib/cw/spoken.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
class
|
5
|
+
#class Numbers provides the Number Testing functionality
|
6
|
+
|
7
|
+
class Spoken
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
@options = options
|
11
|
+
end
|
6
12
|
|
7
|
-
def initialize(options = {})
|
8
|
-
@options = options
|
9
13
|
end
|
10
14
|
|
11
15
|
end
|
data/lib/cw/str.rb
CHANGED
@@ -1,42 +1,74 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
class Str
|
5
|
+
#class Str
|
6
6
|
|
7
|
-
|
7
|
+
class Str
|
8
8
|
|
9
|
-
|
10
|
-
@seperator = ', '
|
11
|
-
end
|
9
|
+
include TextHelpers
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
Params.name + "\n",
|
17
|
-
delim,
|
18
|
-
Params.wpm_str,
|
19
|
-
Params.shuffle_str,
|
20
|
-
Params.word_count_str,
|
21
|
-
Params.word_size_str,
|
22
|
-
beginning_str,
|
23
|
-
ending_str,
|
24
|
-
delim
|
25
|
-
].collect{ |prm| prm.to_s }.join
|
26
|
-
end
|
11
|
+
def initialize
|
12
|
+
@seperator = ', '
|
13
|
+
end
|
27
14
|
|
28
|
-
|
29
|
-
|
30
|
-
|
15
|
+
def to_s
|
16
|
+
delim = delim_str
|
17
|
+
[
|
18
|
+
("#{Cfg.config["name"]}\n" if(Cfg.config["name"])),
|
19
|
+
delim,
|
20
|
+
wpm_str,
|
21
|
+
word_count_str,
|
22
|
+
word_size_str,
|
23
|
+
beginning_str,
|
24
|
+
ending_str,
|
25
|
+
including_str,
|
26
|
+
containing_str,
|
27
|
+
delim
|
28
|
+
].collect{ |prm| prm.to_s }.join
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
def stringify ary
|
32
|
+
ary.join(@seperator)
|
33
|
+
end
|
34
|
+
|
35
|
+
def word_count_str
|
36
|
+
"Word count: #{Cfg.config["word_count"]}\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
def wpm_str
|
40
|
+
"WPM: #{Cfg.config["wpm"]}\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
def word_size_str
|
44
|
+
Cfg.config["size"] ? "Word size: #{Cfg.config["size"]}\n" : nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def delim_str
|
48
|
+
size = Cfg.config["name"] ? Cfg.config["name"].size : 8
|
49
|
+
"#{'=' * size}\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
def beginning_str
|
53
|
+
beginning = Cfg.config["begin"]
|
54
|
+
beginning ? "Beginning: #{stringify beginning}\n" : nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def ending_str
|
58
|
+
ending = Cfg.config["end"]
|
59
|
+
ending ? "Ending: #{stringify ending}\n" : nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def including_str
|
63
|
+
including = Cfg.config["including"]
|
64
|
+
including ? "Including: #{stringify including}\n" : nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def containing_str
|
68
|
+
containing = Cfg.config["containing"]
|
69
|
+
containing ? "Containing: #{stringify containing}\n" : nil
|
70
|
+
end
|
36
71
|
|
37
|
-
def ending_str
|
38
|
-
ending = Params.end
|
39
|
-
ending ? "Ending: #{stringify ending}\n" : nil
|
40
72
|
end
|
41
73
|
|
42
74
|
end
|
data/lib/cw/test_letters.rb
CHANGED
@@ -1,38 +1,30 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
|
5
|
+
class TestLetters < Tester
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def print_test_advice ; print.print_advice('Test Letters') ; end
|
14
|
-
|
15
|
-
def process_input_word_maybe
|
16
|
-
if @word_to_process
|
17
|
-
stream.match_first_active_element @process_input_word # .strip
|
18
|
-
@process_input_word = @word_to_process = nil
|
7
|
+
def process_input_word_maybe
|
8
|
+
if @word_to_process
|
9
|
+
stream.match_first_active_element @process_input_word # .strip
|
10
|
+
@process_input_word = @word_to_process = nil
|
11
|
+
end
|
19
12
|
end
|
20
|
-
end
|
21
13
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
def build_word_maybe
|
15
|
+
@input_word ||= ''
|
16
|
+
@input_word << key_chr if is_relevant_char?
|
17
|
+
move_word_to_process if is_relevant_char?
|
18
|
+
end
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
def process_letter letr
|
21
|
+
letr.downcase!
|
22
|
+
sleep_char_delay letr
|
23
|
+
end
|
32
24
|
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
def print_marked_maybe
|
26
|
+
@popped = stream.pop_next_marked
|
27
|
+
print.char_result(@popped) if(@popped && ! print_letters?)
|
28
|
+
end
|
36
29
|
end
|
37
|
-
|
38
30
|
end
|
data/lib/cw/test_words.rb
CHANGED
@@ -1,46 +1,40 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
|
5
|
+
class TestWords < Tester
|
6
6
|
|
7
|
-
|
8
|
-
@print_letters = Params.print_letters
|
7
|
+
def print_test_advice ; print.print_advice('Test Words') ; end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def print_test_advice ; print.print_advice('Test Words') ; end
|
9
|
+
def print_failed_exit_words
|
10
|
+
until stream.stream_empty?
|
11
|
+
print.fail stream.pop[:value] + ' '
|
12
|
+
end
|
13
|
+
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def process_input_word_maybe
|
16
|
+
if @word_to_process
|
17
|
+
stream.match_last_active_element @process_input_word.strip
|
18
|
+
@process_input_word = @word_to_process = nil
|
19
|
+
end
|
20
20
|
end
|
21
|
-
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def build_word_maybe
|
23
|
+
@input_word ||= ''
|
24
|
+
@input_word << key_chr if is_relevant_char?
|
25
|
+
move_word_to_process if complete_word?
|
27
26
|
end
|
28
|
-
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
28
|
+
def process_letter letr
|
29
|
+
current_word.process_letter letr
|
30
|
+
sleep_char_delay letr
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
def print_marked_maybe
|
34
|
+
@popped = stream.pop_next_marked
|
35
|
+
print.results(@popped) if(@popped && ! print_letters?)
|
36
|
+
end
|
40
37
|
|
41
|
-
def print_marked_maybe
|
42
|
-
@popped = stream.pop_next_marked
|
43
|
-
print.results(@popped) if(@popped && ! print_letters?)
|
44
38
|
end
|
45
39
|
|
46
40
|
end
|