Class: Rusql::BasicCondition
- Defined in:
- lib/rusql/basic_condition.rb
Constant Summary collapse
- TYPES =
%i( equals greater_than greater_than_or_equals in less_than less_than_or_equals like not_equals not_in )
Instance Attribute Summary collapse
-
#right ⇒ Object
Returns the value of attribute right.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #and(condition) ⇒ Object
-
#to_s(indent: " ") ⇒ Object
to make it compatible with complex condition to_s.
Instance Attribute Details
#right ⇒ Object
Returns the value of attribute right.
5 6 7 |
# File 'lib/rusql/basic_condition.rb', line 5 def right @right end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/rusql/basic_condition.rb', line 3 def type @type end |
Instance Method Details
#and(condition) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rusql/basic_condition.rb', line 25 def and(condition) raise Exception.new(Condition, condition.class) unless condition.is_a?(Condition) c = ComplexCondition.new c.type = :and c.add_condition(self) c.add_condition(condition) c end |
#to_s(indent: " ") ⇒ Object
to make it compatible with complex condition to_s
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rusql/basic_condition.rb', line 36 def to_s(indent: " ") # to make it compatible with complex condition to_s case self.type when :equals "#{left.to_s} = #{convert_value(self.right)}" when :greater_than "#{left.to_s} > #{convert_value(self.right)}" when :greater_than_or_equals "#{left.to_s} >= #{convert_value(self.right)}" when :in "#{left.to_s} IN (#{ self.right.map{|v| convert_value(v) }.join(", ") })" when :less_than "#{left.to_s} < #{convert_value(self.right)}" when :less_than_or_equals "#{left.to_s} <= #{convert_value(self.right)}" when :like "#{left.to_s} LIKE #{convert_value(self.right)}" when :not_equals "#{left.to_s} != #{convert_value(self.right)}" when :not_in "#{left.to_s} NOT IN (#{ self.right.map{|v| convert_value(v) }.join(", ") })" end end |