Class: Sus::Be::Or
- Inherits:
-
Object
- Object
- Sus::Be::Or
- Defined in:
- lib/sus/be.rb
Overview
Represents a logical OR combination of multiple predicates.
Instance Method Summary collapse
-
#&(other) ⇒ Object
Combine this predicate with another using AND logic.
-
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
-
#initialize(predicates) ⇒ Or
constructor
Initialize a new OR predicate.
-
#print(output) ⇒ Object
Print a representation of this predicate.
-
#|(other) ⇒ Object
Combine this predicate with another using OR logic.
Constructor Details
#initialize(predicates) ⇒ Or
Initialize a new OR predicate.
57 58 59 |
# File 'lib/sus/be.rb', line 57 def initialize(predicates) @predicates = predicates end |
Instance Method Details
#&(other) ⇒ Object
Combine this predicate with another using AND logic.
95 96 97 |
# File 'lib/sus/be.rb', line 95 def &(other) And.new(self, other) end |
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/sus/be.rb', line 76 def call(assertions, subject) assertions.nested(self) do |assertions| @predicates.each do |predicate| predicate.call(assertions, subject) end if assertions.passed.any? # At least one passed, so we don't care about failures: assertions.failed.clear else # Nothing passed, so we failed: assertions.assert(false, "could not find any matching predicate") end end end |
#print(output) ⇒ Object
Print a representation of this predicate.
63 64 65 66 67 68 69 70 71 |
# File 'lib/sus/be.rb', line 63 def print(output) @predicates.each_with_index do |predicate, index| if index > 0 output.write(" or ", :reset) end predicate.print(output) end end |