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
@@ -1,98 +1,105 @@
1
1
  # encoding: utf-8
2
2
 
3
- class Sentence
4
-
5
- attr_accessor :index #todo
6
-
7
- def text ; @text ||= String.new ; end
8
- def all ; @sentences ; end
9
- def next ; @next = true ; end
10
- def next? ; @next ; end
11
- #todo def forward ; @index += 1 ; end
12
- def forward ; @index ; end
13
- def previous? ; @previous ; end
14
- def repeat? ; @repeat ; end
15
- def change? ; next? || previous? ; end
16
- def change_or_repeat? ; change? || repeat? ; end
17
- def current ; @sentences[@index] ; end
18
- def next_sentence ; @sentences[@index + 1] ; end
19
-
20
- def change
21
- forward if next?
22
- rewind if previous?
23
- end
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
- def rewind
26
- @index = @index <= 1 ? 0 : @index - 1
27
- end
27
+ def rewind
28
+ @index = @index <= 1 ? 0 : @index - 1
29
+ end
28
30
 
29
- def create_progress_maybe progress_file
30
- unless File.exists? progress_file
31
- reset_progress progress_file
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
- def reset_progress progress_file
36
- @index = 0
37
- write_progress progress_file
38
- end
37
+ def reset_progress progress_file
38
+ @index = 0
39
+ write_progress progress_file
40
+ end
39
41
 
40
- def check_end_of_book progress_file
41
- if @index >= @sentences.size
42
- reset_progress progress_file
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
- def read_progress progress_file
47
- create_progress_maybe progress_file
48
- File.open(progress_file, 'r') {|f| @index = f.readline.to_i}
49
- check_end_of_book progress_file
50
- end
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
- def write_progress progress_file
53
- File.open(progress_file, 'w') {|f| f.puts @index.to_s}
54
- end
57
+ def write_progress progress_file
58
+ File.open(progress_file, 'w') {|f| f.puts @index.to_s}
59
+ end
55
60
 
56
- def read_book book
57
- File.open(book, 'r') { |f| text.replace f.readlines(' ').join}
58
- end
61
+ def read_book book
62
+ File.open(book, 'r') { |f| text.replace f.readlines(' ').join}
63
+ end
59
64
 
60
- def cw_chars chr
61
- chr.tr('^a-z0-9\,\=\!\/\?\.', '')
62
- end
65
+ def cw_chars chr
66
+ chr.tr('^a-z0-9\,\=\!\/\?\.', '')
67
+ end
63
68
 
64
- def exclude_non_cw_chars word
65
- cw_chars(word)
66
- end
69
+ def exclude_non_cw_chars word
70
+ cw_chars(word)
71
+ end
67
72
 
68
- def find_all
69
- @sentences = []
70
- @text.gsub!(/\s+/, ' ').downcase!
71
- loop do
72
- sentence_end = @text.index('. ')
73
- unless sentence_end
74
- break
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
- def check_sentence_navigation chr
84
- @next = true if(chr == ']')
85
- @previous = true if(chr == '[')
86
- @repeat = true if(chr == '-')
87
- end
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
- def reset_flags
90
- @next = @previous = @repeat = nil
91
- end
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
@@ -1,11 +1,15 @@
1
1
  # encoding: utf-8
2
2
 
3
- #class Numbers provides the Number Testing functionality
3
+ module CWG
4
4
 
5
- class Spoken
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
@@ -1,11 +1,15 @@
1
1
  # encoding: utf-8
2
2
 
3
- #class Numbers provides the Number Testing functionality
3
+ module CWG
4
4
 
5
- class Spoken
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
@@ -1,42 +1,74 @@
1
1
  # encoding: utf-8
2
2
 
3
- #class Str
3
+ module CWG
4
4
 
5
- class Str
5
+ #class Str
6
6
 
7
- include TextHelpers
7
+ class Str
8
8
 
9
- def initialize
10
- @seperator = ', '
11
- end
9
+ include TextHelpers
12
10
 
13
- def to_s
14
- delim = Params.delim_str
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
- def stringify ary
29
- ary.join(@seperator)
30
- end
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
- def beginning_str
33
- beginning = Params.begin
34
- beginning ? "Beginning: #{stringify beginning}\n" : nil
35
- end
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
@@ -1,38 +1,30 @@
1
1
  # encoding: utf-8
2
2
 
3
- class TestLetters < FileDetails
3
+ module CWG
4
4
 
5
- include Tester
5
+ class TestLetters < Tester
6
6
 
7
- def initialize
8
- @print_letters = Params.print_letters
9
- super()
10
- # print_test_advice
11
- end
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
- def build_word_maybe
23
- @input_word ||= empty_string
24
- @input_word << key_chr if is_relevant_char?
25
- move_word_to_process if is_relevant_char?
26
- end
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
- def process_letter letr
29
- letr.downcase!
30
- sleep_char_delay letr
31
- end
20
+ def process_letter letr
21
+ letr.downcase!
22
+ sleep_char_delay letr
23
+ end
32
24
 
33
- def print_marked_maybe
34
- @popped = stream.pop_next_marked
35
- print.char_result(@popped) if(@popped && ! print_letters?)
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
@@ -1,46 +1,40 @@
1
1
  # encoding: utf-8
2
2
 
3
- class TestWords < FileDetails
3
+ module CWG
4
4
 
5
- include Tester
5
+ class TestWords < Tester
6
6
 
7
- def initialize
8
- @print_letters = Params.print_letters
7
+ def print_test_advice ; print.print_advice('Test Words') ; end
9
8
 
10
- super()
11
-
12
- # print_test_advice
13
- end
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
- def print_failed_exit_words
18
- until stream.stream_empty?
19
- print.fail stream.pop[:value] + ' '
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
- def process_input_word_maybe
24
- if @word_to_process
25
- stream.match_last_active_element @process_input_word.strip
26
- @process_input_word = @word_to_process = nil
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
- def build_word_maybe
31
- @input_word ||= empty_string
32
- @input_word << key_chr if is_relevant_char?
33
- move_word_to_process if complete_word?
34
- end
28
+ def process_letter letr
29
+ current_word.process_letter letr
30
+ sleep_char_delay letr
31
+ end
35
32
 
36
- def process_letter letr
37
- current_word.process_letter letr
38
- sleep_char_delay letr
39
- end
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