Class: MVCLI::Router::Pattern
- Inherits:
-
Object
- Object
- MVCLI::Router::Pattern
- Defined in:
- lib/mvcli/router/pattern.rb
Defined Under Namespace
Instance Method Summary collapse
-
#initialize(pattern) ⇒ Pattern
constructor
A new instance of Pattern.
- #match(input, consumed = [], matchers = @matchers, satisfied = [], bindings = Map.new) ⇒ Object
Constructor Details
#initialize(pattern) ⇒ Pattern
Returns a new instance of Pattern.
6 7 8 |
# File 'lib/mvcli/router/pattern.rb', line 6 def initialize(pattern) @matchers = compile pattern end |
Instance Method Details
#match(input, consumed = [], matchers = @matchers, satisfied = [], bindings = Map.new) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/mvcli/router/pattern.rb', line 10 def match(input, consumed = [], matchers = @matchers, satisfied = [], bindings = Map.new) matcher, *unsatisfied = *matchers value, *rest = *input unless matcher && value && matcher.matches?(value) Match.new input, consumed, matchers, satisfied, bindings else match rest, consumed + [value], unsatisfied, satisfied + [matcher], bindings.merge(matcher.bind(value)) end end |