cw 0.2.4 → 0.3.0
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/.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/book_details.rb
CHANGED
@@ -1,69 +1,58 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
|
5
|
+
class BookDetails
|
6
6
|
|
7
|
-
|
8
|
-
GEM_BOOK_DIRECTORY = HERE + '../../data/text/'
|
9
|
-
GEM_BOOK_NAME = 'book.txt'
|
10
|
-
DEFAULT_BOOK_DIRECTORY = 'books'
|
7
|
+
attr_reader :args
|
11
8
|
|
12
|
-
|
13
|
-
book_directory
|
14
|
-
book_name
|
15
|
-
end
|
9
|
+
include FileDetails
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
return true
|
21
|
-
end
|
11
|
+
def initialize
|
12
|
+
book_directory
|
13
|
+
book_name
|
22
14
|
end
|
23
|
-
false
|
24
|
-
end
|
25
15
|
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
def book_name
|
17
|
+
Cfg.config["book_name"]
|
18
|
+
end
|
29
19
|
|
30
|
-
|
31
|
-
|
32
|
-
if is_default_book_dir?
|
33
|
-
book_dir = DEFAULT_BOOK_DIRECTORY
|
20
|
+
def book_directory
|
21
|
+
File.join ROOT, Cfg.config["book_dir"]
|
34
22
|
end
|
35
|
-
Params.book_dir ||= book_dir
|
36
|
-
end
|
37
23
|
|
38
|
-
|
39
|
-
|
40
|
-
|
24
|
+
def book_location
|
25
|
+
File.expand_path(book_name, book_directory)
|
26
|
+
end
|
41
27
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
28
|
+
def arguments args
|
29
|
+
@args = args
|
30
|
+
@args[:output] = :letter unless @args[:output]
|
31
|
+
if @args[:duration]
|
32
|
+
@timeout = Time.now + @args[:duration] * 60.0
|
33
|
+
end
|
47
34
|
end
|
48
|
-
end
|
49
35
|
|
50
|
-
|
51
|
-
|
52
|
-
|
36
|
+
def session_finished?
|
37
|
+
sentences_complete? || book_timeout?
|
38
|
+
end
|
53
39
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
40
|
+
def sentences_complete?
|
41
|
+
if @args.has_key?(:sentences) && @args[:sentences].is_a?(Fixnum)
|
42
|
+
if @sentence_count_source
|
43
|
+
@sentence_count_source = nil
|
44
|
+
else
|
45
|
+
@args[:sentences] -= 1
|
46
|
+
@sentence_count_source = true
|
47
|
+
end
|
48
|
+
true if(@args[:sentences] < 0)
|
61
49
|
end
|
62
|
-
true if(@args[:sentences] < 0)
|
63
50
|
end
|
64
|
-
end
|
65
51
|
|
66
|
-
|
67
|
-
|
52
|
+
def book_timeout?
|
53
|
+
@timeout && (Time.now > @timeout)
|
54
|
+
end
|
55
|
+
|
68
56
|
end
|
57
|
+
|
69
58
|
end
|
data/lib/cw/cl.rb
CHANGED
@@ -1,121 +1,127 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
class Cl
|
5
|
+
#class Cl performs command-line processing
|
6
6
|
|
7
|
-
|
8
|
-
@tone = {
|
9
|
-
sinewave: 0,
|
10
|
-
sawtooth: 1,
|
11
|
-
squarewave: 2
|
12
|
-
}
|
13
|
-
end
|
7
|
+
class Cl
|
14
8
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
def initialize
|
10
|
+
@tone = {
|
11
|
+
sinewave: 0,
|
12
|
+
sawtooth: 1,
|
13
|
+
squarewave: 2
|
14
|
+
}
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
def cl_wpm
|
18
|
+
wpm = Cfg.config["wpm"]
|
19
|
+
wpm ? "-w #{wpm} " : ''
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
def cl_effective_wpm
|
23
|
+
ewpm = Cfg.config["effective_wpm"]
|
24
|
+
ewpm ? "-e #{ewpm} " : ''
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
def cl_word_spacing
|
28
|
+
ws = Cfg.config["word_spacing"]
|
29
|
+
ws ? "-W #{ws} " : ''
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
def cl_frequency
|
33
|
+
freq = Cfg.config["frequency"]
|
34
|
+
freq ? "-f #{freq} " : ''
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
def cl_squarewave
|
38
|
+
"Cfg.config[\"tone\"] = #{Cfg.config["tone"]}"
|
39
|
+
return '' unless Cfg.config["tone"].to_s == "squarewave"
|
40
|
+
"-T #{@tone[:squarewave]} "
|
41
|
+
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
def cl_sawtooth
|
44
|
+
"Cfg.config[\"tone\"] = #{Cfg.config["tone"]}"
|
45
|
+
return '' unless Cfg.config["tone"].to_s == "sawtooth"
|
46
|
+
"-T #{@tone[:sawtooth]} "
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
def cl_sinewave
|
50
|
+
"Cfg.config[\"tone\"] = #{Cfg.config["tone"]}"
|
51
|
+
return '' unless Cfg.config["tone"].to_s == "sinewave"
|
52
|
+
"-T #{@tone[:sinewave]} "
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
def cl_author
|
56
|
+
author = Cfg.config["author"]
|
57
|
+
author ? "-a \"#{author}\" " : ''
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
def cl_title
|
61
|
+
title = Cfg.config["title"]
|
62
|
+
title ? "-t \"#{title}\" " : ''
|
63
|
+
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
def cl_noise
|
66
|
+
Cfg.config["noise"] ?
|
67
|
+
"-N 5 -B 1000 " : ''
|
68
|
+
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
:medium => "-q 5 ",
|
73
|
-
:low => "-q 9 "
|
74
|
-
}[quality]
|
75
|
-
end
|
70
|
+
def cl_audio_filename
|
71
|
+
"-o \"#{File.expand_path(Cfg.config["audio_filename"], Cfg.config["audio_dir"])}\" "
|
72
|
+
end
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
74
|
+
def coarse_quality(quality)
|
75
|
+
{
|
76
|
+
:high => "-q 1 ",
|
77
|
+
:medium => "-q 5 ",
|
78
|
+
:low => "-q 9 "
|
79
|
+
}[quality]
|
83
80
|
end
|
84
|
-
end
|
85
81
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
def cl_quality
|
83
|
+
quality = Cfg.config["quality"]
|
84
|
+
if quality && quality.class == Fixnum
|
85
|
+
"-q #{quality} "
|
86
|
+
else
|
87
|
+
coarse_quality quality
|
88
|
+
end
|
89
|
+
end
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
cl_frequency,
|
96
|
-
cl_squarewave,
|
97
|
-
cl_sawtooth,
|
98
|
-
cl_sinewave,
|
99
|
-
cl_author,
|
100
|
-
cl_title,
|
101
|
-
cl_noise,
|
102
|
-
cl_audio_filename,
|
103
|
-
cl_quality,
|
104
|
-
cl_command_line
|
105
|
-
].collect{|param| param}.join
|
106
|
-
end
|
91
|
+
def cl_command_line
|
92
|
+
cl = Cfg.config["command_line"]
|
93
|
+
cl ? "#{cl}" : ''
|
94
|
+
end
|
107
95
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
96
|
+
def build_command_line
|
97
|
+
[ cl_wpm,
|
98
|
+
cl_effective_wpm,
|
99
|
+
cl_word_spacing,
|
100
|
+
cl_frequency,
|
101
|
+
cl_squarewave,
|
102
|
+
cl_sawtooth,
|
103
|
+
cl_sinewave,
|
104
|
+
cl_author,
|
105
|
+
cl_title,
|
106
|
+
cl_noise,
|
107
|
+
cl_audio_filename,
|
108
|
+
cl_quality,
|
109
|
+
cl_command_line
|
110
|
+
].collect{|param| param}.join
|
111
|
+
end
|
112
112
|
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
def ebook2cw_path
|
114
|
+
Cfg.config["ebook2cw_path"] || 'ebook2cw'
|
115
|
+
end
|
116
|
+
|
117
|
+
def cl_echo words
|
118
|
+
"echo #{words} | #{ebook2cw_path} #{build_command_line}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def cl_full input
|
122
|
+
"#{ebook2cw_path} #{build_command_line} #{input}"
|
123
|
+
end
|
116
124
|
|
117
|
-
def cl_full input
|
118
|
-
"#{ebook2cw_path} #{build_command_line} #{input}"
|
119
125
|
end
|
120
126
|
|
121
127
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module CWG
|
2
|
+
|
3
|
+
class CommonWords
|
4
|
+
|
5
|
+
include FileDetails
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@words = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def all
|
12
|
+
File.foreach(ENGLISH_DICT).collect do |line|
|
13
|
+
line.chomp
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def low last
|
18
|
+
results = []
|
19
|
+
count = 0
|
20
|
+
File.foreach(ENGLISH_DICT).collect do |line|
|
21
|
+
if count <= last
|
22
|
+
results << line.chomp
|
23
|
+
end
|
24
|
+
count += 1
|
25
|
+
break if count > last
|
26
|
+
end
|
27
|
+
results
|
28
|
+
end
|
29
|
+
|
30
|
+
def mid first, last
|
31
|
+
results = []
|
32
|
+
count = 0
|
33
|
+
File.foreach(ENGLISH_DICT).collect do |line|
|
34
|
+
if (count >= first) && (count <= last)
|
35
|
+
results << line.chomp
|
36
|
+
end
|
37
|
+
count += 1
|
38
|
+
break if count > last
|
39
|
+
end
|
40
|
+
results
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_quantity(quantity = :default)
|
44
|
+
if quantity == :default
|
45
|
+
return [0, 999]
|
46
|
+
elsif quantity.class == Fixnum
|
47
|
+
[0, quantity - 1]
|
48
|
+
(0...quantity).collect {|q| q}
|
49
|
+
elsif quantity.class == Range
|
50
|
+
ary = quantity.to_a
|
51
|
+
return ary[0] - 1, ary[-1] -1
|
52
|
+
# ary.pop
|
53
|
+
# ary.unshift ary[0] - 1
|
54
|
+
# ary
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def read(quantity = :default)
|
59
|
+
if quantity == :all
|
60
|
+
@words = all
|
61
|
+
else
|
62
|
+
qty = parse_quantity(quantity)
|
63
|
+
if qty[0] == 0
|
64
|
+
@words = low qty[-1]
|
65
|
+
else
|
66
|
+
@words = mid qty[0], qty[1]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
@words
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_a
|
73
|
+
@words
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/cw/config.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'parseconfig.rb'
|
2
|
+
|
3
|
+
module CWG
|
4
|
+
|
5
|
+
module Cfg
|
6
|
+
|
7
|
+
include CWG::FileDetails
|
8
|
+
|
9
|
+
CONFIG_METHODS = [
|
10
|
+
:name,:wpm,:effective_wpm,:frequency,:audio_filename,:audio_dir,
|
11
|
+
:book_name,:book_dir,:play_command,:size,:run_default,:word_spacing,
|
12
|
+
:command_line,:author,:title,:quality,:ebook2cw_path,:noise,:tone,
|
13
|
+
:word_count,:volume,:list_colour,:success_colour,:fail_colour,
|
14
|
+
:no_run,:run,:print_letters,:no_print,:use_ebook2cw,
|
15
|
+
:dictionary,:containing,:begin,:end,:including,:word_filename,:max,:min,
|
16
|
+
:exit, :quit
|
17
|
+
]
|
18
|
+
|
19
|
+
def self.config
|
20
|
+
unless @config
|
21
|
+
@config = ParseConfig.new(CONFIG_FILENAME)
|
22
|
+
CONFIG_METHODS.each do |method|
|
23
|
+
unless @config[method.to_s]
|
24
|
+
@config.add method.to_s, nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@config.params["wpm"] = 50 if(ENV["CW_ENV"] == "test")
|
29
|
+
@config.params["effective_wpm"] = 50 if(ENV["CW_ENV"] == "test")
|
30
|
+
@config
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.reset
|
34
|
+
@config = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.reset_param param
|
38
|
+
@config.params[param] = false
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.reset_if_nil param
|
42
|
+
self.reset_param param if @config[param].nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.get_param param
|
46
|
+
self.reset_if_nil param
|
47
|
+
@config[param]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|