Class: Selector::Or
Overview
The composition of several conditions. Requires any of them to be satisfied
Instance Attribute Summary
Attributes inherited from Condition
Class Method Summary collapse
Instance Method Summary collapse
-
#[](value) ⇒ Object
Checks if value satisfies any of composed conditions.
-
#|(other) ⇒ Object
Adds the other condition to the composition (avoids nesting).
Methods inherited from Condition
#!, #&, #-, #==, #attribute, #initialize
Constructor Details
This class inherits a constructor from Selector::Condition
Class Method Details
.new(*attributes) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/selector/or.rb', line 12 def self.new(*attributes) attrs = attributes.uniq - [NOTHING] return NOTHING if attrs.empty? return attrs.first if attrs.count.equal?(1) return ANYTHING if attrs.include? ANYTHING return ANYTHING if (attrs & attrs.map(&:!)).any? super(*attrs) end |
Instance Method Details
#[](value) ⇒ Object
38 39 40 |
# File 'lib/selector/or.rb', line 38 def [](value) attributes.detect { |part| part[value] } ? true : false end |