class Selector::Condition

Describe an immutable condition for selecting values

Attributes

attributes[R]

@!attribute [r] attributes

@return [Array] The array of initialized attributes

Public Class Methods

new(*attributes) click to toggle source

@private

# File lib/selector/condition.rb, line 26
def initialize(*attributes)
  @attributes = attributes
  IceNine.deep_freeze(self)
end

Public Instance Methods

!() click to toggle source

Inverts the condition

@return [Selector::Condition]

# File lib/selector/condition.rb, line 60
def !
  Not.new(self)
end
&(other) click to toggle source

Composes (by AND) the condition to the other condition

@param [Selector::Condition] other

@return [Selector::Condition]

# File lib/selector/condition.rb, line 70
def &(other)
  And.new(self, other)
end
-(other) click to toggle source

Composes (by AND) the condition to inversion of the other condition

This is the same as ‘&(!other)`

@param [Selector::Condition] other

@return [Selector::Condition]

# File lib/selector/condition.rb, line 82
def -(other)
  And.new(self, !other)
end
==(other) click to toggle source

Compares the condition to the other object by type and attributes

@param [Object] other

@return [Boolean]

# File lib/selector/condition.rb, line 37
def ==(other)
  other.instance_of?(self.class) && attributes.eql?(other.attributes)
end
Also aliased as: eql?
[](_value) click to toggle source

@!method [](value) Checks if the value satisfies the condtion

@param [Object] value

@return [Boolean]

@abstract @raise [NotImplementedError] by default

# File lib/selector/condition.rb, line 52
def [](_value)
  fail NotImplementedError.new "#{self.class}#[] not implemented"
end
attribute() click to toggle source

The first attribute

@return [Object]

# File lib/selector/condition.rb, line 21
def attribute
  attributes.first
end
eql?(other)
Alias for: ==
|(other) click to toggle source

Composes (by OR) the condition to the other condition

This is the same as ‘!((!self)&(!other))`

@param [Selector::Condition] other

@return [Selector::Condition]

# File lib/selector/condition.rb, line 94
def |(other)
  Or.new(self, other)
end