Class: Hoozuki::Pattern

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

Instance Method Summary collapse

Constructor Details

#initialize(pattern, engine: :dfa) ⇒ Pattern

Returns a new instance of Pattern.



12
13
14
15
# File 'lib/hoozuki.rb', line 12

def initialize(pattern, engine: :dfa)
  @engine = engine
  @compiled = Hoozuki.compile(pattern, engine: engine)
end

Instance Method Details

#match?(input) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
# File 'lib/hoozuki.rb', line 17

def match?(input)
  case @engine
  when :dfa
    @compiled.match?(input, Hoozuki.__send__(:use_cache?, input))
  when :vm
    Hoozuki::VM::Evaluator.evaluate(@compiled, input, 0, 0)
  else
    raise ArgumentError, "Unknown engine: #{@engine}"
  end
end