Class: Sus::Be::And
- Inherits:
-
Object
- Object
- Sus::Be::And
- Defined in:
- lib/sus/be.rb
Overview
Represents a logical AND 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) ⇒ And
constructor
Initialize a new AND predicate.
-
#print(output) ⇒ Object
Print a representation of this predicate.
-
#|(other) ⇒ Object
Combine this predicate with another using OR logic.
Constructor Details
#initialize(predicates) ⇒ And
Initialize a new AND predicate.
13 14 15 |
# File 'lib/sus/be.rb', line 13 def initialize(predicates) @predicates = predicates end |
Instance Method Details
#&(other) ⇒ Object
Combine this predicate with another using AND logic.
41 42 43 |
# File 'lib/sus/be.rb', line 41 def &(other) And.new(@predicates + [other]) end |
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
32 33 34 35 36 |
# File 'lib/sus/be.rb', line 32 def call(assertions, subject) @predicates.each do |predicate| predicate.call(assertions, subject) end end |
#print(output) ⇒ Object
Print a representation of this predicate.
19 20 21 22 23 24 25 26 27 |
# File 'lib/sus/be.rb', line 19 def print(output) @predicates.each_with_index do |predicate, index| if index > 0 output.write(" and ", :reset) end predicate.print(output) end end |