Class: Matchers::ACMatcher
- Inherits:
-
Object
- Object
- Matchers::ACMatcher
- Defined in:
- lib/aho_corasick.rb
Instance Attribute Summary collapse
-
#trie ⇒ Object
readonly
Returns the value of attribute trie.
Instance Method Summary collapse
-
#initialize(patterns) ⇒ ACMatcher
constructor
A new instance of ACMatcher.
- #matches?(text) ⇒ Boolean
Constructor Details
Instance Attribute Details
#trie ⇒ Object (readonly)
Returns the value of attribute trie.
3 4 5 |
# File 'lib/aho_corasick.rb', line 3 def trie @trie end |
Instance Method Details
#matches?(text) ⇒ Boolean
10 11 12 13 14 15 16 17 18 |
# File 'lib/aho_corasick.rb', line 10 def matches?(text) node = @trie.root text.to_s.split('').each do |char| node = node.failure while node.children[char].nil? # Follow failure if it exists in case pattern doesn't match node = node.children[char] return true unless node.output.nil? end false end |