Class: Messed::Matcher::Conditional

Inherits:
Messed::Matcher show all
Defined in:
lib/messed/matcher.rb

Instance Attribute Summary collapse

Attributes inherited from Messed::Matcher

#destination

Instance Method Summary collapse

Methods inherited from Messed::Matcher

#stop_processing?

Constructor Details

#initialize(body_matcher, other_matchers = nil) ⇒ Conditional

Returns a new instance of Conditional.



14
15
16
17
# File 'lib/messed/matcher.rb', line 14

def initialize(body_matcher, other_matchers = nil)
  @body_matcher = body_matcher
  @other_matchers = other_matchers
end

Instance Attribute Details

#matchesObject

Returns the value of attribute matches.



12
13
14
# File 'lib/messed/matcher.rb', line 12

def matches
  @matches
end

Instance Method Details

#match?(message) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/messed/matcher.rb', line 19

def match?(message)
  matches = true
  self.matches = nil
  if @body_matcher
    matches &&= @body_matcher === message.body
    self.matches = Regexp.last_match if matches && @body_matcher.is_a?(Regexp)
  end

  if @other_matchers
    keys = @other_matchers.keys
    unless matches
      key = keys.pop
      matches &&= @other_matchers[key] === message.send(key)
    end
  end
  matches
end