Class: Selector::And
Overview
The composition of several conditions. Requires each of them to be satisfied
Instance Attribute Summary
Attributes inherited from Condition
Class Method Summary collapse
Instance Method Summary collapse
-
#&(other) ⇒ Object
Adds the other condition to the composition (avoids nesting).
-
#-(other) ⇒ Object
Adds inversion of the other condition to the composition (avoids nesting).
-
#[](value) ⇒ Object
Checks if value satisfies each of composed conditions.
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/and.rb', line 12 def self.new(*attributes) attrs = attributes.uniq - [ANYTHING] return ANYTHING if attrs.empty? return attrs.first if attrs.count.equal?(1) return NOTHING if attrs.include? NOTHING return NOTHING if (attrs & attrs.map(&:!)).any? super(*attrs) end |
Instance Method Details
#&(other) ⇒ Object
Adds the other condition to the composition (avoids nesting)
48 49 50 |
# File 'lib/selector/and.rb', line 48 def &(other) And.new(*attributes, other) end |
#-(other) ⇒ Object
Adds inversion of the other condition to the composition (avoids nesting)
58 59 60 |
# File 'lib/selector/and.rb', line 58 def -(other) And.new(*attributes, !other) end |
#[](value) ⇒ Object
38 39 40 |
# File 'lib/selector/and.rb', line 38 def [](value) attributes.detect { |part| !part[value] } ? false : true end |