Class: MorseCodeInteractive
- Inherits:
-
Object
- Object
- MorseCodeInteractive
- Defined in:
- lib/morsecode.rb
Instance Method Summary collapse
-
#initialize(dash: 'D', dot: 'C', separator: 'B', terminator: "\r", debug: false) ⇒ MorseCodeInteractive
constructor
A new instance of MorseCodeInteractive.
- #input(c) ⇒ Object
- #on_dash ⇒ Object
- #on_dot ⇒ Object
- #on_separator(c) ⇒ Object
- #on_submit(s) ⇒ Object
Constructor Details
#initialize(dash: 'D', dot: 'C', separator: 'B', terminator: "\r", debug: false) ⇒ MorseCodeInteractive
Returns a new instance of MorseCodeInteractive.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/morsecode.rb', line 38 def initialize(dash: 'D', dot: 'C', separator: 'B', terminator: "\r", debug: false) @keys = { dash: dash, dot: dot, separator: separator, terminator: terminator } @mc = '' @debug = debug end |
Instance Method Details
#input(c) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/morsecode.rb', line 53 def input(c) h = { dash: :dash, dot: :dot, separator: :separator, terminator: :submit } if @debug then puts 'c: ' + c.inspect puts '@keys.invert: ' + @keys.invert.inspect end key = @keys.invert[c] puts 'key: ' + key.inspect if @debug found = h[key] puts 'found: ' + found.inspect if @debug method(found).call if found end |
#on_dash ⇒ Object
75 |
# File 'lib/morsecode.rb', line 75 def on_dash() end |
#on_dot ⇒ Object
76 |
# File 'lib/morsecode.rb', line 76 def on_dot() end |
#on_separator(c) ⇒ Object
78 79 80 |
# File 'lib/morsecode.rb', line 78 def on_separator(c) puts 'c: ' + c.inspect end |
#on_submit(s) ⇒ Object
82 83 84 |
# File 'lib/morsecode.rb', line 82 def on_submit(s) puts 's: ' + s.inspect end |