class Selector::And
The composition of several conditions. Requires each of them to be satisfied
@example (see []
)
Public Class Methods
new(*attributes)
click to toggle source
@private
Calls superclass method
# 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
Public Instance Methods
&(other)
click to toggle source
Adds the other condition to the composition (avoids nesting)
@param (see Selector::Composition#&)
@return (see Selector::Composition#&)
# File lib/selector/and.rb, line 48 def &(other) And.new(*attributes, other) end
-(other)
click to toggle source
Adds inversion of the other condition to the composition (avoids nesting)
@param (see Selector::Composition#-)
@return (see Selector::Composition#-)
# File lib/selector/and.rb, line 58 def -(other) And.new(*attributes, !other) end
[](value)
click to toggle source
Checks if value satisfies each of composed conditions
@example left = Selector.new only: /foo/ right = Selector.new only: /bar/ composition = Selector::And.new(left, right) composition[:foo] # => false composition[:bar] # => false composition[:foobar] # => true
@param (see Selector::Composition#[])
@return (see Selector::Composition#[])
# File lib/selector/and.rb, line 38 def [](value) attributes.detect { |part| !part[value] } ? false : true end