Class: MorseMeNicely::Encoder
- Inherits:
-
Object
- Object
- MorseMeNicely::Encoder
- Defined in:
- lib/morse_me_nicely/encoder.rb
Constant Summary collapse
- ENCODING_REFERENCE_PATH =
MORSE_ME_NICELY_PATH + "../../data/morse_reference.yml"
Instance Method Summary collapse
- #encoded_input ⇒ Object
-
#initialize(input_text) ⇒ Encoder
constructor
A new instance of Encoder.
Constructor Details
#initialize(input_text) ⇒ Encoder
Returns a new instance of Encoder.
7 8 9 10 |
# File 'lib/morse_me_nicely/encoder.rb', line 7 def initialize(input_text) @input_text = input_text @encoding_reference = YAML::load_file(ENCODING_REFERENCE_PATH) end |
Instance Method Details
#encoded_input ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/morse_me_nicely/encoder.rb', line 12 def encoded_input validate_input_text @input_text.split(/\n/).map do |line| line.scan(/\w+\.?\,?/).map do |word| translate_word(word) end.join(@encoding_reference["separators"]["word"]) end.join("\n") end |