Class: DB::Model::Statement::Predicate::Composite

Inherits:
Object
  • Object
show all
Defined in:
lib/db/model/statement/predicate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(predicates, operator = "AND") ⇒ Composite

Returns a new instance of Composite.



133
134
135
136
# File 'lib/db/model/statement/predicate.rb', line 133

def initialize(predicates, operator = "AND")
	@predicates = predicates
	@operator = operator
end

Instance Attribute Details

#operatorObject (readonly)

Returns the value of attribute operator.



139
140
141
# File 'lib/db/model/statement/predicate.rb', line 139

def operator
  @operator
end

#predicatesObject (readonly)

Returns the value of attribute predicates.



138
139
140
# File 'lib/db/model/statement/predicate.rb', line 138

def predicates
  @predicates
end

Class Method Details

.for(predicates) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/db/model/statement/predicate.rb', line 125

def self.for(predicates)
	if predicates.size == 0
		return EMPTY
	else
		return self.new(predicates)
	end
end

Instance Method Details

#&(other) ⇒ Object



160
161
162
# File 'lib/db/model/statement/predicate.rb', line 160

def & other
	Composite.new([self, other], "AND")
end

#+(other) ⇒ Object



156
157
158
# File 'lib/db/model/statement/predicate.rb', line 156

def + other
	Composite.new([self, other])
end

#append_to(statement) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/db/model/statement/predicate.rb', line 141

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

Returns:

  • (Boolean)


168
169
170
# File 'lib/db/model/statement/predicate.rb', line 168

def eql?(other)
	self.class.eql?(other.class) && self.predicates.eql?(other.predicates)
end

#hashObject



172
173
174
# File 'lib/db/model/statement/predicate.rb', line 172

def hash
	[self.class, @predicates, @operator].hash
end

#|(other) ⇒ Object



164
165
166
# File 'lib/db/model/statement/predicate.rb', line 164

def | other
	Composite.new([self, other], "OR")
end