Class: CW::Timing

Inherits:
Object
  • Object
show all
Defined in:
lib/cw/timing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTiming

Returns a new instance of Timing.



9
10
11
12
# File 'lib/cw/timing.rb', line 9

def initialize
  @delay_time = 0.0
  @cw_encoding = Encoding.new
end

Instance Attribute Details

#delay_timeObject

Returns the value of attribute delay_time.



6
7
8
# File 'lib/cw/timing.rb', line 6

def delay_time
  @delay_time
end

#start_timeObject

Returns the value of attribute start_time.



7
8
9
# File 'lib/cw/timing.rb', line 7

def start_time
  @start_time
end

Instance Method Details

#append_char_delay(letr, wpm, ewpm) ⇒ Object



81
82
83
# File 'lib/cw/timing.rb', line 81

def append_char_delay letr, wpm, ewpm
  @delay_time += char_delay(letr, wpm, ewpm)
end

#char_delay(char, wpm, ewpm) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/cw/timing.rb', line 72

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

#char_delay_timeout?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/cw/timing.rb', line 42

def char_delay_timeout?
  (Time.now - @start_time) > @delay_time
end

#char_timing(*args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cw/timing.rb', line 46

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

#code_space_timingObject



61
62
63
64
# File 'lib/cw/timing.rb', line 61

def code_space_timing
  @effective_wpm ? 3.0 * effective_dot_ms :
    3.0 * dot_ms
end

#cw_encoding(enc) ⇒ Object



14
15
16
# File 'lib/cw/timing.rb', line 14

def cw_encoding enc
  @cw_encoding.fetch(enc)
end

#dot(wpm) ⇒ Object



18
19
20
# File 'lib/cw/timing.rb', line 18

def dot wpm
  1.2 / wpm.to_f
end

#dot_msObject



22
23
24
# File 'lib/cw/timing.rb', line 22

def dot_ms
  dot @wpm
end

#effective_dot_msObject



34
35
36
# File 'lib/cw/timing.rb', line 34

def effective_dot_ms
  dot @effective_wpm
end

#init_char_timerObject



38
39
40
# File 'lib/cw/timing.rb', line 38

def init_char_timer
  @start_time, @delay_time = Time.now, 0.0
end

#init_print_words_timeoutObject



26
27
28
# File 'lib/cw/timing.rb', line 26

def init_print_words_timeout
  @start_print_time, @delay_print_time = Time.now, 2.0
end

Returns:

  • (Boolean)


30
31
32
# File 'lib/cw/timing.rb', line 30

def print_words_timeout?
  (Time.now - @start_print_time) > @delay_print_time
end

#space_timingObject



66
67
68
69
70
# File 'lib/cw/timing.rb', line 66

def space_timing
  space = 4.0
  @effective_wpm ? space * effective_dot_ms :
    space * dot_ms
end