Class: Tzu::Match

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

Overview

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

Constructor Details

#initialize(outcome, context) ⇒ Match

Returns a new instance of Match.



5
6
7
# File 'lib/tzu/match.rb', line 5

def initialize(outcome, context)
  @outcome, @context, @collection = outcome, context, []
end

Instance Method Details

#invalid(&result_block) ⇒ Object

todo: hash and define_method if more overrides identified



22
23
24
# File 'lib/tzu/match.rb', line 22

def invalid(&result_block)
  push('failure', :validation, result_block)
end

#resultObject



9
10
11
12
13
# File 'lib/tzu/match.rb', line 9

def result
  matcher = @collection.detect { |m| m.matches?(@outcome.type) }
  raise "No match could be made for #{@outcome}" if matcher.nil?
  @context.instance_exec(@outcome.result, &matcher.block)
end