Class: MorseCode::Encoder
- Inherits:
-
Object
- Object
- MorseCode::Encoder
- Includes:
- Cacheable
- Defined in:
- lib/morse_code/encoder.rb
Instance Method Summary collapse
- #encode ⇒ Object
- #encode_with ⇒ Object (also: #dit_dah)
-
#initialize(message = '') ⇒ Encoder
constructor
A new instance of Encoder.
- #wave ⇒ Object
Methods included from Cacheable
Constructor Details
#initialize(message = '') ⇒ Encoder
Returns a new instance of Encoder.
12 13 14 |
# File 'lib/morse_code/encoder.rb', line 12 def initialize( = '') @message = .upcase end |
Instance Method Details
#encode ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/morse_code/encoder.rb', line 16 def encode @encode ||= [].tap do |encode_words| @message.split(/\s+/).each do |word| encode_words.concat(encode_word(word)) end encode_words.pop end.join(' ') end |
#encode_with ⇒ Object Also known as: dit_dah
25 26 27 |
# File 'lib/morse_code/encoder.rb', line 25 def encode_with encode.dup.tap { || .gsub!('.', 'DIT').gsub!('-', 'DAH') } end |