Class: Jisx0402::Tree::Node
- Inherits:
-
Object
- Object
- Jisx0402::Tree::Node
- Defined in:
- lib/jisx0402/tree.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize ⇒ Node
constructor
A new instance of Node.
- #insert(key, remain, val) ⇒ Object
- #search(key, remain) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
25 26 27 28 |
# File 'lib/jisx0402/tree.rb', line 25 def initialize @data = {} @value = nil end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
23 24 25 |
# File 'lib/jisx0402/tree.rb', line 23 def value @value end |
Instance Method Details
#insert(key, remain, val) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/jisx0402/tree.rb', line 30 def insert(key, remain, val) @data[key] ||= Node.new if remain.empty? @data[key].value = val else @data[key].insert(remain.shift, remain, val) end end |
#search(key, remain) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/jisx0402/tree.rb', line 39 def search(key, remain) return nil unless @data[key] if remain.empty? @data[key].values else @data[key].search(remain.shift, remain) end end |
#values ⇒ Object
48 49 50 |
# File 'lib/jisx0402/tree.rb', line 48 def values [value, *@data.values.map(&:values)].compact end |