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.
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.0'
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.add_dependency('wavefile')
20
- spec.add_dependency('paint')
21
- spec.add_dependency('feedjira')
22
- spec.add_dependency('htmlentities')
23
- spec.add_dependency('sanitize')
24
- spec.add_dependency('ruby-progressbar')
25
- spec.add_dependency('rake')
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
- attr_accessor :dry_run
36
- attr_accessor :quit
39
+ #FIXME dry_run
40
+ # attr_accessor :dry_run
37
41
 
38
42
  # Test user against letters rather than words.
39
43
  #
@@ -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
@@ -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
 
@@ -5,16 +5,38 @@ class BookDetails
5
5
  attr_reader :args
6
6
 
7
7
  HERE = File.dirname(__FILE__) + '/'
8
- BOOK_DIRECTORY = HERE + '../../data/text/'
9
- BOOK_NAME = 'adv_of_sh_holmes.txt'
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
- @book_name = BOOK_NAME
13
- @book_directory = BOOK_DIRECTORY
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
- @book_directory + @book_name
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -29,7 +29,7 @@ class KeyInput
29
29
  end
30
30
 
31
31
  def is_punctuation?
32
- [' ', ',', '.', '!', '?'].detect{|letr| letr == @chr}
32
+ [' ', ',', '.', '=', '?'].detect{|letr| letr == @chr}
33
33
  end
34
34
 
35
35
  def is_relevant_char?
@@ -23,6 +23,7 @@ class RepeatWord < FileDetails
23
23
  (words.to_s + space).each_char do |letr|
24
24
  process_letter letr
25
25
  loop do
26
+ do_events
26
27
  process_space_maybe letr
27
28
  process_word_maybe
28
29
  break if timing.char_delay_timeout?