Class: SdbDal::OrCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/sdb_dal/or_condition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(child_conditions = []) ⇒ OrCondition

Returns a new instance of OrCondition.



7
8
9
# File 'lib/sdb_dal/or_condition.rb', line 7

def initialize(child_conditions=[])
  self.child_conditions=child_conditions
end

Instance Attribute Details

#child_conditionsObject

Returns the value of attribute child_conditions.



5
6
7
# File 'lib/sdb_dal/or_condition.rb', line 5

def child_conditions
  @child_conditions
end

Instance Method Details

#add(child_condition) ⇒ Object



11
12
13
# File 'lib/sdb_dal/or_condition.rb', line 11

def add(child_condition)
    self.child_conditions<<child_condition
end

#matches?(domain_object) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sdb_dal/or_condition.rb', line 15

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

#to_sdb_queryObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sdb_dal/or_condition.rb', line 27

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