class Conditions::OrCondition

Checks if either or both of two conditions are true

Public Class Methods

new(predicate) click to toggle source

@param [Array] predicate An array of Hashes representating conditions (Greater than length 2)

Calls superclass method Conditions::BaseCondition::new
# 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

Public Instance Methods

apply(value) click to toggle source

@param [Any] value @return [true] if value matches any condition @return [false] if value matches no conditions

# File lib/conditions.rb, line 113
def apply(value)
  @predicate.map { |x| x.apply(value) }.any?
end