Class: AhoCorasick::TreeNode
- Inherits:
-
Object
- Object
- AhoCorasick::TreeNode
- Defined in:
- lib/aho_corasick.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#suffix ⇒ Object
Returns the value of attribute suffix.
Instance Method Summary collapse
- #add_match(str) ⇒ Object
- #child_for(char) ⇒ Object
- #find(char) ⇒ Object
-
#initialize(parent = nil) ⇒ TreeNode
constructor
A new instance of TreeNode.
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
#children ⇒ Object (readonly)
Returns the value of attribute children.
60 61 62 |
# File 'lib/aho_corasick.rb', line 60 def children @children end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
60 61 62 |
# File 'lib/aho_corasick.rb', line 60 def matches @matches end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
60 61 62 |
# File 'lib/aho_corasick.rb', line 60 def parent @parent end |
#suffix ⇒ Object
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 |