Class: Matchers::ACMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#trieObject (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

Returns:

  • (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