Class: DB::Model::Statement::Predicate::Composite
- Inherits:
-
Object
- Object
- DB::Model::Statement::Predicate::Composite
- Defined in:
- lib/db/model/statement/predicate.rb
Instance Attribute Summary collapse
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#predicates ⇒ Object
readonly
Returns the value of attribute predicates.
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
- #+(other) ⇒ Object
- #append_to(statement) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(predicates, operator = "AND") ⇒ Composite
constructor
A new instance of Composite.
- #|(other) ⇒ Object
Constructor Details
#initialize(predicates, operator = "AND") ⇒ Composite
Returns a new instance of Composite.
116 117 118 119 |
# File 'lib/db/model/statement/predicate.rb', line 116 def initialize(predicates, operator = "AND") @predicates = predicates @operator = operator end |
Instance Attribute Details
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
122 123 124 |
# File 'lib/db/model/statement/predicate.rb', line 122 def operator @operator end |
#predicates ⇒ Object (readonly)
Returns the value of attribute predicates.
121 122 123 |
# File 'lib/db/model/statement/predicate.rb', line 121 def predicates @predicates end |
Class Method Details
.for(predicates) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/db/model/statement/predicate.rb', line 108 def self.for(predicates) if predicates.size == 0 return EMPTY else return self.new(predicates) end end |
Instance Method Details
#&(other) ⇒ Object
143 144 145 |
# File 'lib/db/model/statement/predicate.rb', line 143 def & other Composite.new([self, other], "AND") end |
#+(other) ⇒ Object
139 140 141 |
# File 'lib/db/model/statement/predicate.rb', line 139 def + other Composite.new([self, other]) end |
#append_to(statement) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/db/model/statement/predicate.rb', line 124 def append_to(statement) first = true statement.clause("(") @predicates.each_with_index do |predicate, index| statement.clause(@operator) unless first first = false predicate.append_to(statement) end statement.clause(")") end |
#eql?(other) ⇒ Boolean
151 152 153 |
# File 'lib/db/model/statement/predicate.rb', line 151 def eql?(other) self.class.eql?(other.class) && self.predicates.eql?(other.predicates) end |
#hash ⇒ Object
155 156 157 |
# File 'lib/db/model/statement/predicate.rb', line 155 def hash [self.class, @predicates, @operator].hash end |