Class: AutotaskRuby::QueryXML

Inherits:
Object
  • Object
show all
Defined in:
lib/autotask_ruby/query_xml.rb

Defined Under Namespace

Classes: Condition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ QueryXML

Returns a new instance of QueryXML.

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
# File 'lib/autotask_ruby/query_xml.rb', line 11

def initialize
  yield self
  self.op ||= 'equals'
end

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



9
10
11
# File 'lib/autotask_ruby/query_xml.rb', line 9

def conditions
  @conditions
end

#entityObject

Returns the value of attribute entity.



9
10
11
# File 'lib/autotask_ruby/query_xml.rb', line 9

def entity
  @entity
end

#expressionObject

Returns the value of attribute expression.



9
10
11
# File 'lib/autotask_ruby/query_xml.rb', line 9

def expression
  @expression
end

#fieldObject

Returns the value of attribute field.



9
10
11
# File 'lib/autotask_ruby/query_xml.rb', line 9

def field
  @field
end

#opObject

Returns the value of attribute op.



9
10
11
# File 'lib/autotask_ruby/query_xml.rb', line 9

def op
  @op
end

Instance Method Details

#add_condition(field, op, expression) ⇒ Object



16
17
18
19
# File 'lib/autotask_ruby/query_xml.rb', line 16

def add_condition(field, op, expression)
  self.conditions ||= []
  self.conditions << Condition.new(field, op, expression)
end

#to_sObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/autotask_ruby/query_xml.rb', line 21

def to_s
  Nokogiri::XML::Builder.new do
    sXML do
      cdata(Nokogiri::XML::Builder.new do |xml|
        xml.queryxml do
          xml.entity entity
          xml.query do
            if field
              xml.field field do
                xml.expression expression, op: op
              end
            else
              conditions.each do |condition|
                xml.condition do
                  xml.field condition.field do
                    xml.expression condition.expression,
                                   op: condition.op
                  end
                end
              end
            end
          end
        end
      end.doc.root)
    end
  end.doc.root.to_xml
end