Class: IntacctRuby::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/intacct_ruby/function.rb

Overview

a function to be sent to Intacct. Defined by a function type (e.g. :create), an object type, (e.g. :customer), and parameters.

Constant Summary collapse

ALLOWED_TYPES =
%w(
  readByQuery
  read
  readByName
  readMore
  create
  update
  delete
).freeze
CU_TYPES =
%w(create update).freeze

Instance Method Summary collapse

Constructor Details

#initialize(function_type, object_type: nil, parameters:) ⇒ Function

Returns a new instance of Function.



20
21
22
23
24
25
26
# File 'lib/intacct_ruby/function.rb', line 20

def initialize(function_type, object_type: nil, parameters: )
  @function_type = function_type.to_s
  @object_type = object_type.to_s
  @parameters = parameters

  validate_type!
end

Instance Method Details

#to_xmlObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/intacct_ruby/function.rb', line 28

def to_xml
  xml = Builder::XmlMarkup.new

  xml.function controlid: controlid do
    xml.tag!(@function_type) do
      if CU_TYPES.include?(@function_type)
        xml.tag!(@object_type) do
          xml << parameter_xml(@parameters)
        end
      else
        xml << parameter_xml(@parameters)
      end
    end
  end

  xml.target!
end