Class: TwitterCldr::Utils::Trie::Node
- Inherits:
-
Object
- Object
- TwitterCldr::Utils::Trie::Node
- Defined in:
- lib/twitter_cldr/utils/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
- #has_value? ⇒ 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.
133 134 135 136 |
# File 'lib/twitter_cldr/utils/trie.rb', line 133 def initialize(value = nil, children = {}) @value = value @children = children end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
131 132 133 |
# File 'lib/twitter_cldr/utils/trie.rb', line 131 def value @value end |
Instance Method Details
#child(key) ⇒ Object
138 139 140 |
# File 'lib/twitter_cldr/utils/trie.rb', line 138 def child(key) @children[key] end |
#each_key_and_child(&block) ⇒ Object
154 155 156 |
# File 'lib/twitter_cldr/utils/trie.rb', line 154 def each_key_and_child(&block) @children.each(&block) end |
#has_children? ⇒ Boolean
146 147 148 |
# File 'lib/twitter_cldr/utils/trie.rb', line 146 def has_children? !@children.empty? end |
#has_value? ⇒ Boolean
150 151 152 |
# File 'lib/twitter_cldr/utils/trie.rb', line 150 def has_value? !!value end |
#keys ⇒ Object
158 159 160 |
# File 'lib/twitter_cldr/utils/trie.rb', line 158 def keys @children.keys end |
#set_child(key, child) ⇒ Object
142 143 144 |
# File 'lib/twitter_cldr/utils/trie.rb', line 142 def set_child(key, child) @children[key] = child end |
#subtrie_hash ⇒ Object
166 167 168 169 170 171 |
# File 'lib/twitter_cldr/utils/trie.rb', line 166 def subtrie_hash @children.inject({}) do |memo, (key, child)| memo[key] = [child.value, child.subtrie_hash] memo end end |