Class: TwitterCldr::Utils::Trie::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/utils/trie.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#valueObject

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

Returns:

  • (Boolean)


146
147
148
# File 'lib/twitter_cldr/utils/trie.rb', line 146

def has_children?
  !@children.empty?
end

#has_value?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/twitter_cldr/utils/trie.rb', line 150

def has_value?
  !!value
end

#keysObject



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_hashObject



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

#to_trieObject



162
163
164
# File 'lib/twitter_cldr/utils/trie.rb', line 162

def to_trie
  Trie.new(self.class.new(nil, @children)).lock
end