Class: Eldr::Matcher

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

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Matcher

Returns a new instance of Matcher.



5
6
7
8
# File 'lib/eldr/matcher.rb', line 5

def initialize(path, options = {})
  @path    = path
  @capture = options.delete(:capture)
end

Instance Method Details

#handlerObject



14
15
16
17
18
19
20
21
22
# File 'lib/eldr/matcher.rb', line 14

def handler
  @handler ||=
  case @path
  when String
    Mustermann.new(@path, capture: @capture)
  when Regexp
    /^(?:#{@path})$/
  end
end

#match(pattern) ⇒ Object



10
11
12
# File 'lib/eldr/matcher.rb', line 10

def match(pattern)
  handler.match(pattern)
end