cw 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +11 -0
  4. data/LICENSE +21 -0
  5. data/README.md +21 -0
  6. data/Rakefile +1 -0
  7. data/audio/audio_output.wav +0 -0
  8. data/audio/audio_output.wav0000.mp3 +0 -0
  9. data/audio/dash.wav +0 -0
  10. data/audio/dot.wav +0 -0
  11. data/audio/e_space.wav +0 -0
  12. data/audio/space.wav +0 -0
  13. data/cw.gemspec +18 -0
  14. data/daily.rb +182 -0
  15. data/data/text/abbreviations.txt +1 -0
  16. data/data/text/common_words.txt +90 -0
  17. data/data/text/cw_conversation.txt +1 -0
  18. data/data/text/most_common_words.txt +1 -0
  19. data/data/text/progress.txt +1 -0
  20. data/data/text/q_codes.txt +1 -0
  21. data/data/text/tom_sawyer.txt +6477 -0
  22. data/example.rb +139 -0
  23. data/lib/cw.rb +111 -0
  24. data/lib/cw/alphabet.rb +29 -0
  25. data/lib/cw/audio_player.rb +63 -0
  26. data/lib/cw/book.rb +239 -0
  27. data/lib/cw/book_details.rb +47 -0
  28. data/lib/cw/cl.rb +112 -0
  29. data/lib/cw/cw_dsl.rb +211 -0
  30. data/lib/cw/cw_encoding.rb +56 -0
  31. data/lib/cw/cw_params.rb +29 -0
  32. data/lib/cw/cw_threads.rb +36 -0
  33. data/lib/cw/file_details.rb +13 -0
  34. data/lib/cw/key_input.rb +53 -0
  35. data/lib/cw/monitor.rb +36 -0
  36. data/lib/cw/monitor_keys.rb +37 -0
  37. data/lib/cw/numbers.rb +29 -0
  38. data/lib/cw/print.rb +137 -0
  39. data/lib/cw/process.rb +11 -0
  40. data/lib/cw/progress.rb +27 -0
  41. data/lib/cw/randomize.rb +73 -0
  42. data/lib/cw/repeat_word.rb +91 -0
  43. data/lib/cw/rss.rb +71 -0
  44. data/lib/cw/sentence.rb +78 -0
  45. data/lib/cw/speak.rb +11 -0
  46. data/lib/cw/spoken.rb +11 -0
  47. data/lib/cw/str.rb +67 -0
  48. data/lib/cw/stream.rb +161 -0
  49. data/lib/cw/test_letters.rb +52 -0
  50. data/lib/cw/test_words.rb +59 -0
  51. data/lib/cw/tester.rb +221 -0
  52. data/lib/cw/timing.rb +92 -0
  53. data/lib/cw/tone_generator.rb +225 -0
  54. data/lib/cw/voice.rb +16 -0
  55. data/lib/cw/words.rb +182 -0
  56. data/read_book.rb +33 -0
  57. data/test/run_tests_continuously.rb +4 -0
  58. data/test/test_cw.rb +527 -0
  59. data/test/test_stream.rb +401 -0
  60. metadata +102 -0
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ class CWThreads
4
+
5
+ attr_accessor :threads
6
+
7
+ def initialize context, processes
8
+ @context = context
9
+ @processes = processes
10
+ end
11
+
12
+ def kill
13
+ sleep 0.2
14
+ if @threads.is_a?(Array)
15
+ @threads.each do |th|
16
+ th.exit if th.is_a? Thread
17
+ end
18
+ end
19
+ end
20
+
21
+ def start_threads
22
+ @threads = @processes.collect do |th|
23
+ Thread.new{@context.send th}
24
+ end
25
+ end
26
+
27
+ def wait_for_threads
28
+ @threads.each { |th| th.join }
29
+ end
30
+
31
+ def run
32
+ start_threads
33
+ wait_for_threads
34
+ end
35
+
36
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ class FileDetails
4
+
5
+ def initialize
6
+ @repeat_tone = "../tom2/rpt.mp3"
7
+ @r_tone = "../tom2/r.mp3"
8
+ @sentence_folder = "../tom2/"
9
+ @text_folder = "data/text/"
10
+ @progress_file = 'progress.txt'
11
+ end
12
+
13
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ class KeyInput
4
+
5
+ def initialize
6
+ @quit_ary = Array.new(4)
7
+ end
8
+
9
+ def char
10
+ @chr
11
+ end
12
+
13
+ def read
14
+ @chr = nil
15
+ begin
16
+ system("stty raw -echo")
17
+ @chr = STDIN.getc
18
+ ensure
19
+ system("stty raw -echo")
20
+ end
21
+ end
22
+
23
+ def is_letter?
24
+ @chr >= 'a' && @chr <= 'z'
25
+ end
26
+
27
+ def is_number?
28
+ @chr >= '0' && @chr <= '9'
29
+ end
30
+
31
+ def is_punctuation?
32
+ [' ', ',', '.', '!', '?'].detect{|letr| letr == @chr}
33
+ end
34
+
35
+ def is_relevant_char?
36
+ is_letter? || is_number? || is_punctuation? ? true : false
37
+ end
38
+
39
+ def reset_stdin
40
+ system("stty -raw echo")
41
+ end
42
+
43
+ def quit_input?
44
+ @quit_ary.rotate!
45
+ @quit_ary[3] = @chr
46
+ quit_str = @quit_ary.join.downcase
47
+ if quit_str == 'qqqq'
48
+ reset_stdin
49
+ return true
50
+ end
51
+ end
52
+
53
+ end
data/lib/cw/monitor.rb ADDED
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ # class Monitor
4
+
5
+ class monitor
6
+
7
+ attr_accessor :quit
8
+
9
+ def initialize cw
10
+ @cw = cw
11
+ end
12
+
13
+ def cw
14
+ @cw
15
+ end
16
+
17
+ def monitor_keys
18
+ str = ' '
19
+ chr = ''
20
+ loop do
21
+ begin
22
+ system("stty raw -echo")
23
+ chr = STDIN.getc
24
+ #input_file.print chr
25
+ str[0] = str[1]
26
+ str[1] = chr
27
+ quit = true if str == 'qq'
28
+ @entered_word << chr
29
+ check_match
30
+ ensure
31
+ system("stty -raw echo")
32
+ end
33
+ break if @quit == true
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'thread'
4
+
5
+ class MonitorKeys
6
+ def initialize(cw)
7
+ @cw = cw
8
+ @key_input = KeyInput.new
9
+ @queue = Queue.new
10
+ end
11
+
12
+ def key_input
13
+ @key_input ||= KeyInput.new
14
+ end
15
+
16
+ def empty?
17
+ @queue.empty?
18
+ end
19
+
20
+ def have_data?
21
+ ! empty?
22
+ end
23
+
24
+ def monitor_keys
25
+ loop do
26
+ get_key_input
27
+ break if check_quit_key_input?
28
+ if @cw.quit
29
+ key_input.reset
30
+ break
31
+ end
32
+ check_sentence_navigation key_chr
33
+ build_word_maybe
34
+ end
35
+ end
36
+
37
+ end
data/lib/cw/numbers.rb ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ #class Numbers provides the Number Testing functionality
4
+
5
+ class Numbers
6
+
7
+ def initialize(options = {})
8
+ @options = options
9
+ end
10
+
11
+ def number_list
12
+ '1234567890'
13
+ end
14
+
15
+ def reverse_numbers_maybe
16
+ @numbers.reverse! if @options[:reverse]
17
+ end
18
+
19
+ def shuffle_numbers_maybe
20
+ @numbers = @numbers.split('').shuffle.join if @options[:shuffle]
21
+ end
22
+
23
+ def generate
24
+ @numbers = number_list
25
+ shuffle_numbers_maybe
26
+ reverse_numbers_maybe
27
+ @numbers.split('').join(' ')
28
+ end
29
+ end
data/lib/cw/print.rb ADDED
@@ -0,0 +1,137 @@
1
+ # encoding: utf-8
2
+
3
+ require 'paint'
4
+ require 'io/console'
5
+
6
+ class Print
7
+
8
+ class ProgressPrint
9
+ def colour
10
+ :yellow
11
+ end
12
+
13
+ def print x
14
+ STDOUT.print Paint[x, colour]
15
+ end
16
+ def puts x
17
+ STDOUT.puts Paint[x, colour]
18
+ end
19
+
20
+ def flush
21
+ STDOUT.flush
22
+ end
23
+
24
+ def tty?
25
+ true
26
+ end
27
+ end
28
+
29
+ def initialize
30
+ update_console_size
31
+ reset
32
+ end
33
+
34
+ def console_size
35
+ IO.console.winsize
36
+ rescue LoadError
37
+ [Integer(`tput li`), Integer(`tput co`)]
38
+ end
39
+
40
+ def update_console_size
41
+ @rows, @cols = console_size
42
+ # printf "%d rows by %d columns\n", @rows, @cols
43
+ end
44
+
45
+ def reset
46
+ @print_count = 0
47
+ puts "\r"
48
+ end
49
+
50
+ def newline
51
+ reset
52
+ update_console_size
53
+ end
54
+
55
+ def force_newline_maybe
56
+ if @print_count >= (@cols - 1)
57
+ newline
58
+ true
59
+ end
60
+ end
61
+
62
+ def newline_maybe word
63
+ @print_count += word.size unless force_newline_maybe
64
+ return if((word.size == 1) && (word != ' '))
65
+ if @print_count > (@cols - 10)
66
+ newline
67
+ true
68
+ end
69
+ end
70
+
71
+ def results popped, type = :pass_and_fail
72
+ if popped
73
+ value = popped[:value]
74
+ success = popped[:success]
75
+
76
+ newline_maybe value
77
+
78
+ print Paint["#{value} ", :blue] if success
79
+ print Paint["#{value} ", :red ] unless (success || type == :pass_only)
80
+ return true
81
+ end
82
+ end
83
+
84
+ def char_result popped
85
+ if popped
86
+ value = popped[:value]
87
+ success = popped[:success]
88
+
89
+ unless newline_maybe value
90
+ #return if @print_count == 0 && value == ' '
91
+ value = '_' if((value == ' ') && (success != true))
92
+ print Paint["#{value}", :blue] if success
93
+ print Paint["#{value}", :red ] unless success
94
+ return true
95
+ end
96
+ end
97
+ end
98
+
99
+ def heading
100
+ puts ("*" * "Current Sentence is duration: secs".length) + "\r"
101
+ end
102
+
103
+ def print_blue(word)
104
+ print Paint[word, :blue]
105
+ cursor_pos = word.size
106
+ (12 - cursor_pos).times{print ' '}
107
+ end
108
+
109
+ def print_green(word)
110
+ print_blue(word)
111
+ print Paint["#{word} \r\n", :green]
112
+ end
113
+
114
+ def print_red word
115
+ print Paint["#{word }\r\n", :red]
116
+ end
117
+
118
+ def prn_red word
119
+ print Paint["#{word}", :red]
120
+ end
121
+
122
+ def print_fail(word, attempt)
123
+ print_blue(word)
124
+ print Paint["#{attempt }\r\n", :red]
125
+ end
126
+
127
+ def prn(word)
128
+ newline_maybe word
129
+ return if(@print_count == 0 && word == ' ')
130
+ print Paint["#{word}", :blue]
131
+ end
132
+
133
+ def print_advice name
134
+ puts "#{name.to_s}: Press Q 4 times to Exit"
135
+ end
136
+
137
+ end
data/lib/cw/process.rb ADDED
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ module Process
4
+ def exist?(pid)
5
+ Process.kill(0, pid)
6
+ true
7
+ rescue Errno::ESRCH
8
+ false
9
+ end
10
+ module_function :exist?
11
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'ruby-progressbar'
4
+ #require 'paint'
5
+
6
+ class Progress
7
+
8
+ def initialize(title)
9
+ @title = title
10
+ end
11
+
12
+ def init size
13
+ @progress =
14
+ ProgressBar.
15
+ create(total: size,
16
+ title: 'Compiling',
17
+ progress_mark: '.',
18
+ length: 40,
19
+ output: Print::ProgressPrint.new,
20
+ format: "%t: |%B| %p% ")
21
+ end
22
+
23
+ def increment
24
+ @progress.increment
25
+ end
26
+
27
+ end
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ #class Randomize provides character randomising
4
+
5
+ class Randomize
6
+
7
+ def initialize(options, chars)
8
+ @options = options
9
+ @chars = chars
10
+ end
11
+
12
+ def word_count
13
+ @options[:count] ? @options[:count] : 50
14
+ end
15
+
16
+ def size
17
+ @options[:size] ? @options[:size] : 4
18
+ end
19
+
20
+ def lengthen_chars
21
+ @chars += @chars while(@chars.length < size)
22
+ end
23
+
24
+ def shuffle_chars
25
+ @chars.shuffle!
26
+ end
27
+
28
+ def take_chars size
29
+ @chars.take size
30
+ end
31
+
32
+ def chars_to_alpha
33
+ @chrs.collect{|char| char.chr}.join
34
+ end
35
+
36
+ def has_no_letter?
37
+ @alpha[/[a-zA-Z]+/] == @alpha
38
+ end
39
+
40
+ def has_no_number?
41
+ @alpha[/[0-9]+/] == @alpha
42
+ end
43
+
44
+ def missing_letters_or_numbers?
45
+ if @options && @options[:letters_numbers]
46
+ return true if has_no_letter?
47
+ return true if has_no_number?
48
+ end
49
+ end
50
+
51
+ def process_chars
52
+ lengthen_chars
53
+ shuffle_chars
54
+ @chrs = take_chars size
55
+ @alpha = chars_to_alpha
56
+ end
57
+
58
+ def chars_processed?
59
+ process_chars
60
+ ! missing_letters_or_numbers?
61
+ end
62
+
63
+ def generate
64
+ @words, count = [], word_count
65
+ while count > 0
66
+ next unless chars_processed?
67
+ @words.push @alpha
68
+ count -= 1
69
+ end
70
+ @words
71
+ end
72
+
73
+ end