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/process.rb
CHANGED
data/lib/cw/progress.rb
CHANGED
@@ -1,27 +1,30 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'ruby-progressbar'
|
4
|
-
#require 'paint'
|
5
4
|
|
6
|
-
|
5
|
+
module CWG
|
7
6
|
|
8
|
-
|
9
|
-
@title = title
|
10
|
-
end
|
7
|
+
class Progress
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
def initialize(title)
|
10
|
+
@title = title
|
11
|
+
end
|
12
|
+
|
13
|
+
def init size
|
14
|
+
@progress =
|
15
|
+
ProgressBar.
|
16
|
+
create(total: size,
|
17
|
+
title: 'Compiling',
|
18
|
+
progress_mark: '.',
|
19
|
+
length: 40,
|
20
|
+
output: Print::ProgressPrint.new,
|
21
|
+
format: "%t: |%B| %p% ")
|
22
|
+
end
|
23
|
+
|
24
|
+
def increment
|
25
|
+
@progress.increment
|
26
|
+
end
|
22
27
|
|
23
|
-
def increment
|
24
|
-
@progress.increment
|
25
28
|
end
|
26
29
|
|
27
30
|
end
|
data/lib/cw/randomize.rb
CHANGED
@@ -1,73 +1,77 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
class Randomize
|
5
|
+
#class Randomize provides character randomising
|
6
6
|
|
7
|
-
|
8
|
-
@options = options
|
9
|
-
@chars = chars
|
10
|
-
end
|
7
|
+
class Randomize
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def initialize(options, chars)
|
10
|
+
@options = options
|
11
|
+
@chars = chars
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def word_count
|
15
|
+
@options[:count] ? @options[:count] : 50
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def size
|
19
|
+
@options[:size] ? @options[:size] : 4
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def lengthen_chars
|
23
|
+
@chars += @chars while(@chars.length < size)
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
def shuffle_chars
|
27
|
+
@chars.shuffle!
|
28
|
+
end
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
def take_chars size
|
31
|
+
@chars.take size
|
32
|
+
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def chars_to_alpha
|
35
|
+
@chrs.collect{|char| char.chr}.join
|
36
|
+
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
def has_no_letter?
|
39
|
+
@alpha[/[a-zA-Z]+/] == @alpha
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
return true if has_no_letter?
|
47
|
-
return true if has_no_number?
|
42
|
+
def has_no_number?
|
43
|
+
@alpha[/[0-9]+/] == @alpha
|
48
44
|
end
|
49
|
-
end
|
50
45
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
46
|
+
def missing_letters_or_numbers?
|
47
|
+
if @options && @options[:letters_numbers]
|
48
|
+
return true if has_no_letter?
|
49
|
+
return true if has_no_number?
|
50
|
+
end
|
51
|
+
end
|
57
52
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
53
|
+
def process_chars
|
54
|
+
lengthen_chars
|
55
|
+
shuffle_chars
|
56
|
+
@chrs = take_chars size
|
57
|
+
@alpha = chars_to_alpha
|
58
|
+
end
|
62
59
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
next unless chars_processed?
|
67
|
-
@words.push @alpha
|
68
|
-
count -= 1
|
60
|
+
def chars_processed?
|
61
|
+
process_chars
|
62
|
+
! missing_letters_or_numbers?
|
69
63
|
end
|
70
|
-
|
64
|
+
|
65
|
+
def generate
|
66
|
+
@words, count = [], word_count
|
67
|
+
while count > 0
|
68
|
+
next unless chars_processed?
|
69
|
+
@words.push @alpha
|
70
|
+
count -= 1
|
71
|
+
end
|
72
|
+
@words
|
73
|
+
end
|
74
|
+
|
71
75
|
end
|
72
76
|
|
73
77
|
end
|
data/lib/cw/repeat_word.rb
CHANGED
@@ -1,87 +1,80 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
|
5
|
+
class RepeatWord < Tester
|
6
6
|
|
7
|
-
|
8
|
-
super
|
9
|
-
@repeat_word = true
|
10
|
-
end
|
7
|
+
#overloaded #todo
|
11
8
|
|
12
|
-
|
9
|
+
# def print_failed_exit_words
|
10
|
+
# until stream.stream_empty?
|
11
|
+
# word = stream.pop[:value]
|
12
|
+
# end
|
13
|
+
# puts "empty!"
|
14
|
+
# end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def print_words words
|
17
|
+
timing.init_char_timer
|
18
|
+
(words.to_s + ' ').each_char do |letr|
|
19
|
+
process_letter letr
|
20
|
+
loop do
|
21
|
+
do_events
|
22
|
+
process_space_maybe letr
|
23
|
+
process_word_maybe
|
24
|
+
break if timing.char_delay_timeout?
|
25
|
+
end
|
26
|
+
print.success letr if print_letters?
|
27
|
+
end
|
18
28
|
end
|
19
|
-
end
|
20
29
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
do_events
|
27
|
-
process_space_maybe letr
|
28
|
-
process_word_maybe
|
29
|
-
break if timing.char_delay_timeout?
|
30
|
+
def process_input_word_maybe
|
31
|
+
# puts "process_input_word_maybe"
|
32
|
+
if @word_to_process
|
33
|
+
stream.match_last_active_element @process_input_word.strip
|
34
|
+
@process_input_word = @word_to_process = nil
|
30
35
|
end
|
31
|
-
print.success letr if print_letters?
|
32
|
-
break if quit?
|
33
36
|
end
|
34
|
-
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
def build_word_maybe
|
39
|
+
@input_word ||= ''
|
40
|
+
@input_word << key_chr if is_relevant_char?
|
41
|
+
move_word_to_process if complete_word?
|
40
42
|
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def build_word_maybe
|
44
|
-
@input_word ||= empty_string
|
45
|
-
@input_word << key_chr if is_relevant_char?
|
46
|
-
move_word_to_process if complete_word?
|
47
|
-
end
|
48
43
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
def print_marked_maybe
|
55
|
-
@popped = stream.pop_next_marked
|
56
|
-
print.results(@popped, :pass_only) if(@popped && ! print_letters?)
|
57
|
-
end
|
44
|
+
def process_letter letr
|
45
|
+
current_word.process_letter letr
|
46
|
+
sleep_char_delay letr
|
47
|
+
end
|
58
48
|
|
59
|
-
|
49
|
+
def print_marked_maybe
|
50
|
+
@popped = stream.pop_next_marked
|
51
|
+
print.results(@popped, :pass_only) if(@popped && ! print_letters?)
|
52
|
+
end
|
60
53
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
def test_env
|
55
|
+
if(ENV["CW_ENV"] == "test")
|
56
|
+
@words = []
|
57
|
+
return true
|
58
|
+
end
|
65
59
|
end
|
66
|
-
temp
|
67
|
-
end
|
68
60
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
61
|
+
def run words
|
62
|
+
temp_words = words.all
|
63
|
+
temp_words.each do |word|
|
64
|
+
loop do
|
65
|
+
break if test_env
|
66
|
+
@input_word, @words = '', Words.new
|
67
|
+
Cfg.config.params["quit"] = false
|
68
|
+
@words.assign word
|
69
|
+
@threads = CWThreads.new(self, thread_processes)
|
70
|
+
@threads.start_threads
|
71
|
+
@threads.wait_for_threads
|
72
|
+
@play = nil
|
73
|
+
system("stty -raw echo")
|
74
|
+
break unless failed?
|
75
|
+
end
|
81
76
|
end
|
82
|
-
break if
|
77
|
+
# break if Cfg.config["exit"]
|
83
78
|
end
|
84
|
-
reset_stdin
|
85
|
-
print.newline
|
86
79
|
end
|
87
80
|
end
|
data/lib/cw/reveal.rb
CHANGED
@@ -1,47 +1,48 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
|
5
|
+
class Reveal < Tester
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
7
|
+
def initialize
|
8
|
+
@reveal_buf = ''
|
9
|
+
puts 'Reveal mode:'
|
10
|
+
end
|
12
11
|
|
13
|
-
|
12
|
+
def print_test_advice ; print.print_advice('Test Words') ; end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def print_failed_exit_words
|
15
|
+
until stream.stream_empty?
|
16
|
+
@reveal_buf += stream.pop[:value] + ' '
|
17
|
+
end
|
18
|
+
print.success @reveal_buf
|
18
19
|
end
|
19
|
-
print.success @reveal_buf
|
20
|
-
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
def process_input_word_maybe
|
22
|
+
if @word_to_process
|
23
|
+
stream.match_last_active_element @process_input_word.strip
|
24
|
+
@process_input_word = @word_to_process = nil
|
25
|
+
end
|
26
26
|
end
|
27
|
-
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
def build_word_maybe
|
29
|
+
@input_word ||= ''
|
30
|
+
@input_word << key_chr if is_relevant_char?
|
31
|
+
move_word_to_process if complete_word?
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def process_letter letr
|
35
|
+
current_word.process_letter letr
|
36
|
+
sleep_char_delay letr
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
def print_marked_maybe
|
40
|
+
@popped = stream.pop_next_marked
|
41
|
+
if @popped
|
42
|
+
@reveal_buf += @popped[:value] + ' '
|
43
|
+
end
|
44
44
|
end
|
45
|
+
|
45
46
|
end
|
46
47
|
|
47
48
|
end
|
data/lib/cw/rss.rb
CHANGED
@@ -1,62 +1,66 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
module CWG
|
4
4
|
|
5
|
-
class Rss
|
5
|
+
#class Rss
|
6
6
|
|
7
|
-
|
7
|
+
class Rss
|
8
8
|
|
9
|
-
|
10
|
-
{
|
11
|
-
bbc: 'http://feeds.bbci.co.uk/news/rss.xml',
|
12
|
-
reuters: 'http://feeds.reuters.com/Reuters/worldNews?format=xml',
|
13
|
-
guardian: 'http://www.theguardian.com/world/rss',
|
14
|
-
quotation: 'http://feeds.feedburner.com/quotationspage/qotd'
|
15
|
-
}
|
16
|
-
end
|
9
|
+
include TextHelpers
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
def sources
|
12
|
+
{
|
13
|
+
bbc: 'http://feeds.bbci.co.uk/news/rss.xml',
|
14
|
+
reuters: 'http://feeds.reuters.com/Reuters/worldNews?format=xml',
|
15
|
+
guardian: 'http://www.theguardian.com/world/rss',
|
16
|
+
quotation: 'http://feeds.feedburner.com/quotationspage/qotd'
|
17
|
+
}
|
18
|
+
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
20
|
+
def source src
|
21
|
+
sources.has_key?(src) ? sources[src] : sources[:quotation]
|
22
|
+
end
|
23
|
+
|
24
|
+
def read_rss(src, article_count = 3)
|
25
|
+
require 'feedjira'
|
26
|
+
require "htmlentities"
|
27
|
+
require 'sanitize'
|
28
|
+
coder = HTMLEntities.new
|
29
|
+
url = source(src)
|
30
|
+
# return a Hash - each url having a Feedjira::Feed object
|
31
|
+
feed = Feedjira::Feed.fetch_and_parse url
|
32
|
+
entry_count = 0
|
33
|
+
@rss_articles = []
|
34
|
+
feed.entries.each do |entry|
|
35
|
+
title = entry.title
|
36
|
+
unless(title.include?('VIDEO:') ||
|
37
|
+
title.include?('In pictures:') ||
|
38
|
+
title.include?('Morning business round-up'))
|
39
|
+
words = entry.summary
|
40
|
+
entry_count += 1
|
41
|
+
end
|
42
|
+
@rss_articles << (Sanitize.clean coder.decode words).split(',')
|
43
|
+
break if entry_count >= article_count
|
39
44
|
end
|
40
|
-
@rss_articles << (Sanitize.clean coder.decode words).split(',')
|
41
|
-
break if entry_count >= article_count
|
42
45
|
end
|
43
|
-
@rss_flag = true
|
44
|
-
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
def inc_article_index
|
48
|
+
@article_index += 1
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def article_index
|
52
|
+
@article_index || @article_index = 0
|
53
|
+
end
|
54
|
+
|
55
|
+
def next_article
|
56
|
+
temp = @rss_articles[article_index]
|
57
|
+
return unless temp
|
58
|
+
inc_article_index
|
59
|
+
quote = ''
|
60
|
+
temp.map { |i| quote += i }
|
61
|
+
(quote.split.collect { |article| cw_chars(article.strip.delete("\"").downcase)})
|
62
|
+
end
|
53
63
|
|
54
|
-
def next_article
|
55
|
-
temp = @rss_articles[article_index]
|
56
|
-
return unless temp
|
57
|
-
inc_article_index
|
58
|
-
quote = ''
|
59
|
-
temp.map { |i| quote += i }
|
60
|
-
(quote.split.collect { |article| cw_chars(article.strip.delete("\"").downcase)})
|
61
64
|
end
|
65
|
+
|
62
66
|
end
|