class Rusql::ComplexCondition
Constants
- TYPES
Attributes
conditions[R]
type[R]
Public Class Methods
new()
click to toggle source
# File lib/rusql/complex_condition.rb, line 11 def initialize @conditions = [] end
Public Instance Methods
add_condition(c)
click to toggle source
# File lib/rusql/complex_condition.rb, line 15 def add_condition(c) raise TypeException.new(Condition, c.class) unless c.is_a?(Condition) @conditions << c end
and(condition)
click to toggle source
# File lib/rusql/complex_condition.rb, line 27 def and(condition) new_condition = ComplexCondition.new new_condition.type = :and if self.type == :and self.conditions.each do |c| new_condition.add_condition(c) end else new_condition.add_condition(self) end new_condition.add_condition(condition) new_condition end
or(condition)
click to toggle source
# File lib/rusql/complex_condition.rb, line 43 def or(condition) new_condition = ComplexCondition.new new_condition.type = :or if self.type == :or self.conditions.each do |c| new_condition.add_condition(c) end else new_condition.add_condition(self) end new_condition.add_condition(condition) new_condition end
to_s(indent_level: 1, multiline: true)
click to toggle source
# File lib/rusql/complex_condition.rb, line 59 def to_s(indent_level: 1, multiline: true) if multiline indent = " "*indent_level indent_out = " "*(indent_level-1) "(\n" + indent + self.conditions.map{ |c| c.to_s(indent_level: indent_level+1, multiline: true) }.join("\n#{indent}#{self.type.to_s.upcase} ") + "\n#{indent_out})" else self.conditions.map{ |c| c.to_s(indent_level: indent_level, multiline: multiline) }.join(" #{self.type.to_s.upcase} ") end end
type=(t)
click to toggle source
# File lib/rusql/complex_condition.rb, line 21 def type=(t) raise Exception.new("Expected type to be one of #{ TYPES.map(&:to_s).join(", ") }") unless TYPES.include?(t) @type = t end