Class: Messed::Matcher::Conditional
- Inherits:
-
Messed::Matcher
- Object
- Messed::Matcher
- Messed::Matcher::Conditional
- Defined in:
- lib/messed/matcher.rb
Instance Attribute Summary collapse
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
Attributes inherited from Messed::Matcher
Instance Method Summary collapse
-
#initialize(body_matcher, other_matchers = nil) ⇒ Conditional
constructor
A new instance of Conditional.
- #match?(message) ⇒ Boolean
Methods inherited from Messed::Matcher
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
#matches ⇒ Object
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
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?() matches = true self.matches = nil if @body_matcher matches &&= @body_matcher === .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] === .send(key) end end matches end |