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.



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

#operatorObject (readonly)

Returns the value of attribute operator.



122
123
124
# File 'lib/db/model/statement/predicate.rb', line 122

def operator
  @operator
end

#predicatesObject (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

Returns:

  • (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

#hashObject



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

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

#|(other) ⇒ Object



147
148
149
# File 'lib/db/model/statement/predicate.rb', line 147

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