Class: CodeMorse
- Inherits:
-
Object
- Object
- CodeMorse
- Defined in:
- lib/code_morse.rb
Instance Attribute Summary collapse
-
#morse_tree ⇒ Object
readonly
Returns the value of attribute morse_tree.
Instance Method Summary collapse
- #call(params) ⇒ Object
-
#initialize ⇒ CodeMorse
constructor
A new instance of CodeMorse.
Constructor Details
#initialize ⇒ CodeMorse
Returns a new instance of CodeMorse.
10 11 12 13 |
# File 'lib/code_morse.rb', line 10 def initialize @morse_tree = Morse::Tree.new @morse_tree.learn(MORSE_CHARS) end |
Instance Attribute Details
#morse_tree ⇒ Object (readonly)
Returns the value of attribute morse_tree.
8 9 10 |
# File 'lib/code_morse.rb', line 8 def morse_tree @morse_tree end |
Instance Method Details
#call(params) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/code_morse.rb', line 15 def call(params) params = (params.is_a?(Array) ? params : [params]).flatten out = [] params.each do |param| if param =~ /\w/ out.push(Morsify.new.call(param)) else # TODO: add regex for recognizing morse code only out.push(morse_tree.humanize(param)) end end out.join(' ') end |