SusSourceSusBeAnd

class And

Represents a logical AND combination of multiple predicates.

Definitions

def initialize(predicates)

Initialize a new AND predicate.

Signature

parameter predicates Array

The predicates to combine with AND logic.

Implementation

def initialize(predicates)
	@predicates = predicates
end

def print(output)

Print a representation of this predicate.

Signature

parameter output Output

The output target.

Implementation

def print(output)
	@predicates.each_with_index do |predicate, index|
		if index > 0
			output.write(" and ", :reset)
		end
		
		predicate.print(output)
	end
end

def call(assertions, subject)

Evaluate this predicate against a subject.

Signature

parameter assertions Assertions

The assertions instance to use.

parameter subject Object

The subject to evaluate.

Implementation

def call(assertions, subject)
	@predicates.each do |predicate|
		predicate.call(assertions, subject)
	end
end

def &(other)

Combine this predicate with another using AND logic.

Signature

parameter other Object

Another predicate to combine.

returns And

A new AND predicate.

Implementation

def &(other)
	And.new(@predicates + [other])
end

def |(other)

Combine this predicate with another using OR logic.

Signature

parameter other Object

Another predicate to combine.

returns Or

A new OR predicate.

Implementation

def |(other)
	Or.new([self, other])
end