Class: Cuprum::Matching::MatchClause

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#blockObject

Returns the value of attribute block

Returns:

  • (Object)

    the current value of block



12
13
14
# File 'lib/cuprum/matching/match_clause.rb', line 12

def block
  @block
end

#errorObject

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



12
13
14
# File 'lib/cuprum/matching/match_clause.rb', line 12

def error
  @error
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



12
13
14
# File 'lib/cuprum/matching/match_clause.rb', line 12

def status
  @status
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of 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.

Parameters:

Returns:

  • (Integer)

    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.

Returns:

  • (Boolean)

    true if the error and value match, otherwise false.



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.

Returns:

  • (Boolean)

    true if the result matches, otherwise false.



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