Class: AutotaskAPI::QueryXML

Inherits:
Object
  • Object
show all
Defined in:
lib/autotask_api/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:


6
7
8
9
# File 'lib/autotask_api/query_xml.rb', line 6

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

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions


4
5
6
# File 'lib/autotask_api/query_xml.rb', line 4

def conditions
  @conditions
end

#entityObject

Returns the value of attribute entity


4
5
6
# File 'lib/autotask_api/query_xml.rb', line 4

def entity
  @entity
end

#expressionObject

Returns the value of attribute expression


4
5
6
# File 'lib/autotask_api/query_xml.rb', line 4

def expression
  @expression
end

#fieldObject

Returns the value of attribute field


4
5
6
# File 'lib/autotask_api/query_xml.rb', line 4

def field
  @field
end

#opObject

Returns the value of attribute op


4
5
6
# File 'lib/autotask_api/query_xml.rb', line 4

def op
  @op
end

Instance Method Details

#add_condition(field, op, expression) ⇒ Object


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

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

#to_sObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/autotask_api/query_xml.rb', line 16

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_s
end