Module: Quickbooks::Parser::XMLGeneration

Includes:
Quickbooks::Parser, XMLParsing, Support::Inflection
Included in:
QbxmlBase
Defined in:
lib/quickbooks/parser/xml_generation.rb

Constant Summary

Constants included from XMLParsing

Quickbooks::Parser::XMLParsing::COMMENT_END, Quickbooks::Parser::XMLParsing::COMMENT_MATCHER, Quickbooks::Parser::XMLParsing::COMMENT_START, Quickbooks::Parser::XMLParsing::XML_COMMENT, Quickbooks::Parser::XMLParsing::XML_DOCUMENT, Quickbooks::Parser::XMLParsing::XML_ELEMENT, Quickbooks::Parser::XMLParsing::XML_NODE, Quickbooks::Parser::XMLParsing::XML_NODE_SET, Quickbooks::Parser::XMLParsing::XML_TEXT

Instance Method Summary collapse

Methods included from Support::Inflection

#underscore

Methods included from XMLParsing

#cleanup_qbxml, #leaf_node?, #parse_leaf_node_data, #parse_xml_attributes

Instance Method Details

#to_qbxmlObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/quickbooks/parser/xml_generation.rb', line 6

def to_qbxml
  xml_doc = Nokogiri::XML(self.class.xml_template)
  root = xml_doc.root
  log.debug "to_qbxml#nodes_size: #{root.children.size}"

  # replace all children nodes of the template with populated data nodes
  xml_nodes = []
  root.children.each do |xml_template|
    next unless xml_template.is_a? XML_ELEMENT
    attr_name = underscore(xml_template)
    log.debug "to_qbxml#attr_name: #{attr_name}"

    val = self.send(attr_name)
    next unless val && val.not_blank?

    xml_nodes += build_qbxml_nodes(xml_template, val)
    log.debug "to_qbxml#val: #{val}"
  end

  log.debug "to_qbxml#xml_nodes_size: #{xml_nodes.size}"
  root.children = xml_nodes.join('')
  set_xml_attributes!(root)
  root.to_s
end