Class: MorseCode::Decoder

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

Instance Method Summary collapse

Constructor Details

#initialize(message = '') ⇒ Decoder

Returns a new instance of Decoder.



5
6
7
# File 'lib/morse_code/decoder.rb', line 5

def initialize(message = '')
  @message = message.dup
end

Instance Method Details

#decodeObject



9
10
11
12
13
14
15
# File 'lib/morse_code/decoder.rb', line 9

def decode
  [].tap do |decode_words|
    @message.split(/\s+/).each do |word|
      decode_words << (MorseCode::DECODE_MAP[word] || word)
    end
  end.join(' ')
end

#decode_withObject Also known as: dit_dah_to



17
18
19
20
# File 'lib/morse_code/decoder.rb', line 17

def decode_with
  @message.tap { |message| message.gsub!('DIT', '.'); message.gsub!('DAH', '-') }
  decode
end