Module: Quickbooks::Support::QBXML

Included in:
API, QbxmlBase, QbxmlParser
Defined in:
lib/quickbooks/support/qbxml.rb

Constant Summary collapse

XML_DOCUMENT =
Nokogiri::XML::Document
XML_NODE_SET =
Nokogiri::XML::NodeSet
XML_NODE =
Nokogiri::XML::Node
XML_ELEMENT =
Nokogiri::XML::Element
XML_COMMENT =
Nokogiri::XML::Comment
XML_TEXT =
Nokogiri::XML::Text
COMMENT_START =
"<!--"
COMMENT_END =
"-->"
COMMENT_MATCHER =
/\A#{COMMENT_START}.*#{COMMENT_END}\z/

Instance Method Summary collapse

Instance Method Details

#cleanup_qbxml(qbxml) ⇒ Object

remove all comment lines and empty nodes



24
25
26
27
28
29
# File 'lib/quickbooks/support/qbxml.rb', line 24

def cleanup_qbxml(qbxml)
  qbxml = qbxml.split('\n')
  qbxml.map! { |l| l.strip }
  qbxml.reject! { |l| l =~ COMMENT_MATCHER }
  qbxml.join('')
end

#is_leaf_node?(xml_obj) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/quickbooks/support/qbxml.rb', line 15

def is_leaf_node?(xml_obj)
  xml_obj.children.size == 1 && xml_obj.children.first.class == XML_TEXT
end

#qbxml_class_defined?(name) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/quickbooks/support/qbxml.rb', line 19

def qbxml_class_defined?(name)
  get_schema_namespace.constants.include?(name)
end

#set_required_attributes(xml_obj) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/quickbooks/support/qbxml.rb', line 31

def set_required_attributes(xml_obj)
  required_attributes = get_required_xml_attributes
  xml_obj.attributes.each do |a,v|
    if required_attributes.keys.include?(a)
      xml_obj.set_attribute(a, required_attributes[a])
    else
      xml_obj.remove_attribute(a)
    end
  end
  xml_obj
end