Class: TwitterCldr::Collation::Trie::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#valueObject

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

Returns:

  • (Boolean)


145
146
147
# File 'lib/twitter_cldr/collation/trie.rb', line 145

def has_children?
  !@children.empty?
end

#keysObject



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_hashObject



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

#to_trieObject



157
158
159
# File 'lib/twitter_cldr/collation/trie.rb', line 157

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