Class: OrientDB::SQL::ConditionExpression

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/orientdb/sql/common.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ ConditionExpression

Returns a new instance of ConditionExpression.



200
201
202
203
# File 'lib/orientdb/sql/common.rb', line 200

def initialize(type)
  @type       = type
  @conditions = []
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



198
199
200
# File 'lib/orientdb/sql/common.rb', line 198

def conditions
  @conditions
end

Instance Method Details

#<=>(other) ⇒ Object



242
243
244
# File 'lib/orientdb/sql/common.rb', line 242

def <=>(other)
  to_s <=> other.to_s
end

#add(*conds) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/orientdb/sql/common.rb', line 209

def add(*conds)
  conds.each do |cond|
    case cond
      when ConditionExpression
        conditions << cond.to_s
      when Hash
        cond.each { |k, v| conditions << "#{k} = #{Query.quote(v)}" }
      when Array
        cond.each { |x| conditions << x.to_s }
      else
        conditions << cond.to_s
    end
  end
end

#clearObject



224
225
226
# File 'lib/orientdb/sql/common.rb', line 224

def clear
  @conditions = []
end

#conditions_strObject



228
229
230
# File 'lib/orientdb/sql/common.rb', line 228

def conditions_str
  conditions.join(' AND ')
end

#parens_conditions_strObject



232
233
234
# File 'lib/orientdb/sql/common.rb', line 232

def parens_conditions_str
  conditions.size > 1 ? "(#{conditions_str})" : conditions_str
end

#to_sObject



236
237
238
# File 'lib/orientdb/sql/common.rb', line 236

def to_s
  "#{type} #{parens_conditions_str} "
end

#typeObject



205
206
207
# File 'lib/orientdb/sql/common.rb', line 205

def type
  @type.to_s.upcase.gsub('_', ' ')
end