Class: MorseCode

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

Instance Method Summary collapse

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_mcObject



20
21
22
# File 'lib/morsecode.rb', line 20

def to_mc
  @input_string.split(//).map{|char| @h.invert[char]}.join('4')
end

#to_sObject



16
17
18
# File 'lib/morsecode.rb', line 16

def to_s
  @input_string.split(/4/).map{|code| @h[code]}.join()
end