Class: MorseCode
- Inherits:
-
Object
- Object
- MorseCode
- Defined in:
- lib/morsecode.rb
Instance Method Summary collapse
-
#initialize(input_string) ⇒ MorseCode
constructor
A new instance of MorseCode.
- #to_mc ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(input_string) ⇒ MorseCode
Returns a new instance of MorseCode.
9 10 11 12 13 14 |
# File 'lib/morsecode.rb', line 9 def initialize(input_string) buffer = File.open(File.dirname(__FILE__) + '/morsecode.xml','r').read @h = Hash[Dynarex.new(buffer).to_h.map{|x| x.values[0..1]}] @input_string = input_string end |
Instance Method Details
#to_mc ⇒ Object
20 21 22 |
# File 'lib/morsecode.rb', line 20 def to_mc @input_string.split(//).map{|char| @h.invert[char]}.join('4') end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/morsecode.rb', line 16 def to_s @input_string.split(/4/).map{|code| @h[code]}.join() end |