Class: Conditions::OrCondition

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

Overview

Checks if either or both of two conditions are true

Instance Method Summary collapse

Constructor Details

#initialize(predicate) ⇒ OrCondition

Returns a new instance of OrCondition.

Parameters:

  • predicate (Array)

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

Raises:



102
103
104
105
106
107
# File 'lib/conditions.rb', line 102

def initialize(predicate)
  raise ConditionError, 'Or 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 any condition

  • (false)

    if value matches no conditions



113
114
115
# File 'lib/conditions.rb', line 113

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