Class: Morse::Tree
- Inherits:
-
Object
- Object
- Morse::Tree
- Defined in:
- lib/morse/tree.rb
Defined Under Namespace
Classes: Node
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #humanize(morse_string) ⇒ Object
-
#initialize ⇒ Tree
constructor
A new instance of Tree.
- #learn(morse_table = {}) ⇒ Object
Constructor Details
#initialize ⇒ Tree
Returns a new instance of Tree.
7 8 9 |
# File 'lib/morse/tree.rb', line 7 def initialize @root = Node.new(nil, ' ') end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/morse/tree.rb', line 5 def root @root end |
Instance Method Details
#humanize(morse_string) ⇒ Object
17 18 19 20 |
# File 'lib/morse/tree.rb', line 17 def humanize(morse_string) out = get_recursively(morse_string, @root) out end |
#learn(morse_table = {}) ⇒ Object
11 12 13 14 15 |
# File 'lib/morse/tree.rb', line 11 def learn(morse_table = {}) morse_table.each do |letter,morse| @root = push_recursively(@root, letter, morse, 0) end end |