Class: Matchers::ACMatcher
- Inherits:
-
Object
- Object
- Matchers::ACMatcher
- Defined in:
- lib/matcher.rb
Instance Attribute Summary collapse
-
#trie ⇒ Object
readonly
Returns the value of attribute trie.
Instance Method Summary collapse
- #find(text) ⇒ Object
-
#initialize(patterns) ⇒ ACMatcher
constructor
A new instance of ACMatcher.
- #matches?(text) ⇒ Boolean
Constructor Details
#initialize(patterns) ⇒ ACMatcher
Returns a new instance of ACMatcher.
8 9 10 11 |
# File 'lib/matcher.rb', line 8 def initialize(patterns) patterns = (patterns || []).compact.reject(&:empty?) @machine = ACAutomaton.new patterns end |
Instance Attribute Details
#trie ⇒ Object (readonly)
Returns the value of attribute trie.
6 7 8 |
# File 'lib/matcher.rb', line 6 def trie @trie end |
Instance Method Details
#find(text) ⇒ Object
19 20 21 22 23 |
# File 'lib/matcher.rb', line 19 def find(text) return false if text.nil? || text == '' @machine.find(text) end |
#matches?(text) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/matcher.rb', line 13 def matches?(text) return false if text.nil? || text == '' @machine.matches? text.to_s end |