class RailsSimpleSearch::ConditionGroup
Public Class Methods
new(item=nil)
click to toggle source
# File lib/sql_handler.rb, line 145 def initialize(item=nil) if item @condition_item = item else @children = [] end end
Public Instance Methods
add(cg)
click to toggle source
# File lib/sql_handler.rb, line 153 def add(cg) if leaf? raise "It's not allowed to add child into leaf node" end @children << cg if cg end
empty?()
click to toggle source
# File lib/sql_handler.rb, line 171 def empty? (@children && @children.empty?) ? true : false end
leaf?()
click to toggle source
# File lib/sql_handler.rb, line 167 def leaf? @condition_item ? true : false end
set_relation(and_or)
click to toggle source
# File lib/sql_handler.rb, line 160 def set_relation(and_or) if leaf? raise "It's not needed to set relation for leaf node" end @relation = and_or end
to_ar_condition()
click to toggle source
# File lib/sql_handler.rb, line 175 def to_ar_condition condition = [] if leaf? i = @condition_item condition << "#{i.field} #{i.verb}" if i.verb == 'in' condition[0] << " (?)" else condition[0] << " ?" end condition << i.value else tmp = @children.map(&:to_ar_condition) condition << "(" + tmp.map(&:first).join(" #{@relation} ") + ")" tmp.each do |t| (1..(t.length-1)).each do |index| condition << t[index] end end end condition end