Class: Cuprum::Matching::MatchClause
- Inherits:
-
Struct
- Object
- Struct
- Cuprum::Matching::MatchClause
- Includes:
- Comparable
- Defined in:
- lib/cuprum/matching/match_clause.rb
Overview
Value object that represents a potential result match for a Matcher.
Should not be instantiated directly; instead, instantiate a Cuprum::Matcher or include Cuprum::Matching in a custom class.
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#error ⇒ Object
Returns the value of attribute error.
-
#status ⇒ Object
Returns the value of attribute status.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
The comparison result.
-
#matches_details?(error:, value:) ⇒ Boolean
Checks if the match clause matches the specified error and value.
-
#matches_result?(result:) ⇒ Boolean
Checks if the match clause matches the given result.
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
12 13 14 |
# File 'lib/cuprum/matching/match_clause.rb', line 12 def block @block end |
#error ⇒ Object
Returns the value of attribute error
12 13 14 |
# File 'lib/cuprum/matching/match_clause.rb', line 12 def error @error end |
#status ⇒ Object
Returns the value of attribute status
12 13 14 |
# File 'lib/cuprum/matching/match_clause.rb', line 12 def status @status end |
#value ⇒ Object
Returns the value of attribute value
12 13 14 |
# File 'lib/cuprum/matching/match_clause.rb', line 12 def value @value end |
Instance Method Details
#<=>(other) ⇒ Integer
Returns the comparison result.
18 19 20 21 22 23 24 25 26 |
# File 'lib/cuprum/matching/match_clause.rb', line 18 def <=>(other) return nil unless other.is_a?(Cuprum::Matching::MatchClause) cmp = compare(value, other.value) return cmp unless cmp.zero? compare(error, other.error) end |
#matches_details?(error:, value:) ⇒ Boolean
Checks if the match clause matches the specified error and value.
31 32 33 34 35 36 |
# File 'lib/cuprum/matching/match_clause.rb', line 31 def matches_details?(error:, value:) return false unless matches_detail?(error, self.error) return false unless matches_detail?(value, self.value) true end |
#matches_result?(result:) ⇒ Boolean
Checks if the match clause matches the given result.
41 42 43 44 45 46 |
# File 'lib/cuprum/matching/match_clause.rb', line 41 def matches_result?(result:) return false unless error.nil? || result.error.is_a?(error) return false unless value.nil? || result.value.is_a?(value) true end |