Class: CWG::Timing
- Inherits:
-
Object
- Object
- CWG::Timing
- Defined in:
- /Users/martyn/cw/cw_clone/lib/cw/timing.rb
Instance Attribute Summary (collapse)
-
- (Object) delay_time
Returns the value of attribute delay_time.
-
- (Object) start_time
Returns the value of attribute start_time.
Instance Method Summary (collapse)
- - (Object) append_char_delay(letr, wpm, ewpm)
- - (Object) char_delay(char, wpm, ewpm)
- - (Boolean) char_delay_timeout?
- - (Object) char_timing(*args)
- - (Object) code_space_timing
- - (Object) cw_encoding(enc)
- - (Object) dot(wpm)
- - (Object) dot_ms
- - (Object) effective_dot_ms
- - (Object) init_char_timer
- - (Object) init_play_words_timeout
- - (Object) init_print_words_timeout
-
- (Timing) initialize
constructor
A new instance of Timing.
- - (Boolean) play_words_timeout?
- - (Boolean) print_words_timeout?
- - (Object) space_timing
Constructor Details
- (Timing) initialize
Returns a new instance of Timing
10 11 12 13 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 10 def initialize @delay_time = 0.0 @cw_encoding = CwEncoding.new end |
Instance Attribute Details
- (Object) delay_time
Returns the value of attribute delay_time
7 8 9 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 7 def delay_time @delay_time end |
- (Object) start_time
Returns the value of attribute start_time
8 9 10 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 8 def start_time @start_time end |
Instance Method Details
- (Object) append_char_delay(letr, wpm, ewpm)
90 91 92 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 90 def append_char_delay letr, wpm, ewpm @delay_time += char_delay(letr, wpm, ewpm) end |
- (Object) char_delay(char, wpm, ewpm)
81 82 83 84 85 86 87 88 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 81 def char_delay(char, wpm, ewpm) @wpm, @effective_wpm = wpm, ewpm if(char != ' ') char_timing(cw_encoding(char)) unless(char == ' ') else space_timing end end |
- (Boolean) char_delay_timeout?
51 52 53 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 51 def char_delay_timeout? (Time.now - @start_time) > @delay_time end |
- (Object) char_timing(*args)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 55 def char_timing(* args) timing = 0 args.flatten.each do |arg| case arg when :dot then timing += 2 when :dash then timing += 4 else puts "Error! invalid morse symbol - was #{arg}" end end timing -= 1 timing = timing.to_f * dot_ms timing + code_space_timing end |
- (Object) code_space_timing
70 71 72 73 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 70 def code_space_timing @effective_wpm ? 3.0 * effective_dot_ms : 3.0 * dot_ms end |
- (Object) cw_encoding(enc)
15 16 17 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 15 def cw_encoding enc @cw_encoding.fetch(enc) end |
- (Object) dot(wpm)
19 20 21 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 19 def dot wpm 1.2 / wpm.to_f end |
- (Object) dot_ms
23 24 25 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 23 def dot_ms dot @wpm end |
- (Object) effective_dot_ms
43 44 45 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 43 def effective_dot_ms dot @effective_wpm end |
- (Object) init_char_timer
47 48 49 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 47 def init_char_timer @start_time, @delay_time = Time.now, 0.0 end |
- (Object) init_play_words_timeout
35 36 37 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 35 def init_play_words_timeout @start_play_time, @delay_play_time = Time.now, 2.0 end |
- (Object) init_print_words_timeout
27 28 29 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 27 def init_print_words_timeout @start_print_time, @delay_print_time = Time.now, 2.0 end |
- (Boolean) play_words_timeout?
39 40 41 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 39 def play_words_timeout? (Time.now - @start_play_time) > @delay_play_time end |
- (Boolean) print_words_timeout?
31 32 33 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 31 def print_words_timeout? (Time.now - @start_print_time) > @delay_print_time end |
- (Object) space_timing
75 76 77 78 79 |
# File '/Users/martyn/cw/cw_clone/lib/cw/timing.rb', line 75 def space_timing space = 4.0 @effective_wpm ? space * effective_dot_ms : space * dot_ms end |