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.



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

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



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

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

#resultObject



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

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