Class: AhoCorasick::TreeNode

Inherits:
Object
  • Object
show all
Defined in:
lib/aho_corasick.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ TreeNode

Returns a new instance of TreeNode.



53
54
55
56
57
58
# File 'lib/aho_corasick.rb', line 53

def initialize(parent=nil)
  @parent = parent
  @suffix = nil
  @matches = []
  @children = {}
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



60
61
62
# File 'lib/aho_corasick.rb', line 60

def children
  @children
end

#matchesObject (readonly)

Returns the value of attribute matches.



60
61
62
# File 'lib/aho_corasick.rb', line 60

def matches
  @matches
end

#parentObject (readonly)

Returns the value of attribute parent.



60
61
62
# File 'lib/aho_corasick.rb', line 60

def parent
  @parent
end

#suffixObject

Returns the value of attribute suffix.



61
62
63
# File 'lib/aho_corasick.rb', line 61

def suffix
  @suffix
end

Instance Method Details

#add_match(str) ⇒ Object



68
69
70
# File 'lib/aho_corasick.rb', line 68

def add_match(str)
  @matches << str
end

#child_for(char) ⇒ Object



72
73
74
# File 'lib/aho_corasick.rb', line 72

def child_for(char)
  @children[char.to_sym] ||= TreeNode.new(self)
end

#find(char) ⇒ Object



64
65
66
# File 'lib/aho_corasick.rb', line 64

def find(char)
  @children[char.to_sym] || (suffix && suffix.find(char.to_sym))
end