Class: TwitterCldr::Collation::Trie::Node
- Inherits:
-
Object
- Object
- TwitterCldr::Collation::Trie::Node
- Defined in:
- lib/twitter_cldr/collation/trie.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #child(key) ⇒ Object
- #each_key_and_child(&block) ⇒ Object
- #has_children? ⇒ Boolean
-
#initialize(value = nil, children = {}) ⇒ Node
constructor
A new instance of Node.
- #keys ⇒ Object
- #set_child(key, child) ⇒ Object
- #subtrie_hash ⇒ Object
- #to_trie ⇒ Object
Constructor Details
#initialize(value = nil, children = {}) ⇒ Node
Returns a new instance of Node.
132 133 134 135 |
# File 'lib/twitter_cldr/collation/trie.rb', line 132 def initialize(value = nil, children = {}) @value = value @children = children end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
130 131 132 |
# File 'lib/twitter_cldr/collation/trie.rb', line 130 def value @value end |
Instance Method Details
#child(key) ⇒ Object
137 138 139 |
# File 'lib/twitter_cldr/collation/trie.rb', line 137 def child(key) @children[key] end |
#each_key_and_child(&block) ⇒ Object
149 150 151 |
# File 'lib/twitter_cldr/collation/trie.rb', line 149 def each_key_and_child(&block) @children.each(&block) end |
#has_children? ⇒ Boolean
145 146 147 |
# File 'lib/twitter_cldr/collation/trie.rb', line 145 def has_children? !@children.empty? end |
#keys ⇒ Object
153 154 155 |
# File 'lib/twitter_cldr/collation/trie.rb', line 153 def keys @children.keys end |
#set_child(key, child) ⇒ Object
141 142 143 |
# File 'lib/twitter_cldr/collation/trie.rb', line 141 def set_child(key, child) @children[key] = child end |
#subtrie_hash ⇒ Object
161 162 163 164 165 166 |
# File 'lib/twitter_cldr/collation/trie.rb', line 161 def subtrie_hash @children.inject({}) do |memo, (key, child)| memo[key] = [child.value, child.subtrie_hash] memo end end |