Class: StringMetric::Levenshtein::TrieNode

Inherits:
Object
  • Object
show all
Defined in:
lib/string_metric/levenshtein/trie_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTrieNode

Returns a new instance of TrieNode.



8
9
10
11
# File 'lib/string_metric/levenshtein/trie_node.rb', line 8

def initialize
  @word = nil
  @children = {}
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



6
7
8
# File 'lib/string_metric/levenshtein/trie_node.rb', line 6

def children
  @children
end

#wordObject

Returns the value of attribute word.



6
7
8
# File 'lib/string_metric/levenshtein/trie_node.rb', line 6

def word
  @word
end

Instance Method Details

#insert(word) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/string_metric/levenshtein/trie_node.rb', line 13

def insert(word)
  node = self
  word.codepoints.each do |char|
    node.children[char] = TrieNode.new unless node.children.key?(char)
    node = node.children[char]
  end
  node.word = word
end