Class: MorseCode::Decoder
- Inherits:
-
Object
- Object
- MorseCode::Decoder
- Defined in:
- lib/morse_code/decoder.rb
Instance Method Summary collapse
- #decode ⇒ Object
- #decode_with ⇒ Object (also: #dit_dah_to)
-
#initialize(message = '') ⇒ Decoder
constructor
A new instance of Decoder.
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 = .dup end |
Instance Method Details
#decode ⇒ Object
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_with ⇒ Object Also known as: dit_dah_to
17 18 19 20 |
# File 'lib/morse_code/decoder.rb', line 17 def decode_with @message.tap { || .gsub!('DIT', '.'); .gsub!('DAH', '-') } decode end |