Class: Selector::Condition
- Inherits:
-
Object
- Object
- Selector::Condition
- Includes:
- Comparable
- Defined in:
- lib/selector/condition.rb
Overview
Describe an immutable condition for selecting values
Instance Attribute Summary collapse
-
#attributes ⇒ Array
readonly
The array of initialized attributes.
Instance Method Summary collapse
-
#! ⇒ Selector::Condition
Inverts the condition.
-
#&(other) ⇒ Selector::Condition
Composes (by AND) the condition to the other condition.
-
#-(other) ⇒ Selector::Condition
Composes (by AND) the condition to inversion of the other condition.
-
#==(other) ⇒ Boolean
Compares the condition to the other object by type and attributes.
-
#[](value) ⇒ Boolean
abstract
Checks if the value satisfies the condtion.
-
#attribute ⇒ Object
The first attribute.
-
#initialize(*attributes) ⇒ Condition
constructor
A new instance of Condition.
-
#|(other) ⇒ Selector::Condition
Composes (by OR) the condition to the other condition.
Constructor Details
#initialize(*attributes) ⇒ Condition
Returns a new instance of Condition.
26 27 28 29 |
# File 'lib/selector/condition.rb', line 26 def initialize(*attributes) @attributes = attributes IceNine.deep_freeze(self) end |
Instance Attribute Details
#attributes ⇒ Array (readonly)
Returns The array of initialized attributes.
15 16 17 |
# File 'lib/selector/condition.rb', line 15 def attributes @attributes end |
Instance Method Details
#! ⇒ Selector::Condition
Inverts the condition
59 60 61 |
# File 'lib/selector/condition.rb', line 59 def ! Not.new(self) end |
#&(other) ⇒ Selector::Condition
Composes (by AND) the condition to the other condition
69 70 71 |
# File 'lib/selector/condition.rb', line 69 def &(other) And.new(self, other) end |
#-(other) ⇒ Selector::Condition
Composes (by AND) the condition to inversion of the other condition
This is the same as ‘&(!other)`
81 82 83 |
# File 'lib/selector/condition.rb', line 81 def -(other) And.new(self, !other) end |
#==(other) ⇒ Boolean
Compares the condition to the other object by type and attributes
37 38 39 |
# File 'lib/selector/condition.rb', line 37 def ==(other) other.instance_of?(self.class) && attributes.eql?(other.attributes) end |
#[](value) ⇒ Boolean
Checks if the value satisfies the condtion
51 52 53 |
# File 'lib/selector/condition.rb', line 51 def [](_value) fail NotImplementedError.new "#{self.class}#[] not implemented" end |
#attribute ⇒ Object
The first attribute
21 22 23 |
# File 'lib/selector/condition.rb', line 21 def attribute attributes.first end |
#|(other) ⇒ Selector::Condition
Composes (by OR) the condition to the other condition
This is the same as ‘!((!self)&(!other))`
93 94 95 |
# File 'lib/selector/condition.rb', line 93 def |(other) Or.new(self, other) end |