Sha256: 15137edd542ec44be361489cd2ac98b2b1c1a2bb838ae2b903e18953d303c8e9

Contents?: true

Size: 1.12 KB

Versions: 11

Compression:

Stored size: 1.12 KB

Contents

module SdbDal
 

class OrCondition
    attr_accessor :child_conditions
    
  def initialize(child_conditions=[])
    self.child_conditions=child_conditions
  end
  
  def add(child_condition)
      self.child_conditions<<child_condition
  end
  
  def matches?(domain_object)
      
      self.child_conditions.each do | condition|
          if condition.respond_to?(:matches?)
              if condition.matches?(domain_object)
                  return true
              end
                   
          end
      end
      return false
  end
  def to_sdb_query
      first =true
      query=""
      count=0
      self.child_conditions.each do | condition|
        count=count+1
          if ! first
              if count>4
                  query<< " ] union [ "
                  count=0
              else
                  query<< " or "
              end
          end
              first=false
          
          if condition.respond_to?(:to_sdb_query)
             
              query << condition.to_sdb_query
          else  
               query << condition.to_s      
          end
      end
      return query
  end
end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sdb_dal-0.0.4 ./lib/sdb_dal/or_condition.rb
sdb_dal-0.0.5 ./lib/sdb_dal/or_condition.rb
sdb_dal-0.0.8 ./lib/sdb_dal/or_condition.rb
sdb_dal-0.0.11 ./lib/sdb_dal/or_condition.rb
sdb_dal-0.0.1 ./lib/sdb_dal/or_condition.rb
sdb_dal-0.0.12 ./lib/sdb_dal/or_condition.rb
sdb_dal-0.0.6 ./lib/sdb_dal/or_condition.rb
sdb_dal-0.0.7 ./lib/sdb_dal/or_condition.rb
sdb_dal-0.0.2 ./lib/sdb_dal/or_condition.rb
sdb_dal-0.0.3 ./lib/sdb_dal/or_condition.rb
sdb_dal-0.0.9 ./lib/sdb_dal/or_condition.rb