Class: Conditions::AndCondition

Inherits:
BaseCondition show all
Defined in:
lib/conditions.rb

Overview

Checks if two conditions are true

Instance Method Summary collapse

Constructor Details

#initialize(predicate) ⇒ AndCondition

Returns a new instance of AndCondition.

Parameters:

  • predicate (Array)

    An array of Hashes representating conditions (Greater than length 2)

Raises:



81
82
83
84
85
86
# File 'lib/conditions.rb', line 81

def initialize(predicate)
  raise ConditionError, 'And condition predicate must be an array of conditions' unless predicate.is_a?(Array) && predicate.length > 1

  predicate.map! { |x| Object.const_get("Conditions::#{x['class']}").new(x['predicate']) }
  super(predicate)
end

Instance Method Details

#apply(value) ⇒ true, false

Parameters:

  • value (Any)

Returns:

  • (true)

    if value matches all conditions

  • (false)

    if value does not match one condition



92
93
94
# File 'lib/conditions.rb', line 92

def apply(value)
  @predicate.map { |x| x.apply(value) }.all?
end