Module: Quickbooks::Parser::XMLParsing
- Included in:
- XMLGeneration, QbxmlParser
- Defined in:
- lib/quickbooks/parser/xml_parsing.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
-
#cleanup_qbxml(qbxml) ⇒ Object
remove all comment lines and empty nodes.
- #leaf_node?(xml_obj) ⇒ Boolean
- #parse_leaf_node_data(xml_obj) ⇒ Object
- #parse_xml_attributes(xml_obj) ⇒ Object
Instance Method Details
#cleanup_qbxml(qbxml) ⇒ Object
remove all comment lines and empty nodes
17 18 19 20 21 22 |
# File 'lib/quickbooks/parser/xml_parsing.rb', line 17 def cleanup_qbxml(qbxml) qbxml = qbxml.split('\n') qbxml.map! { |l| l.strip } qbxml.reject! { |l| l =~ COMMENT_MATCHER } qbxml.join('') end |
#leaf_node?(xml_obj) ⇒ Boolean
24 25 26 |
# File 'lib/quickbooks/parser/xml_parsing.rb', line 24 def leaf_node?(xml_obj) (xml_obj.children.size == 0 || xml_obj.children.size == 1) && xml_obj.attributes.empty? end |
#parse_leaf_node_data(xml_obj) ⇒ Object
28 29 30 31 32 |
# File 'lib/quickbooks/parser/xml_parsing.rb', line 28 def parse_leaf_node_data(xml_obj) attr_name = underscore(xml_obj) text_node = xml_obj.children.first [attr_name, text_node && text_node.text] end |
#parse_xml_attributes(xml_obj) ⇒ Object
34 35 36 37 |
# File 'lib/quickbooks/parser/xml_parsing.rb', line 34 def parse_xml_attributes(xml_obj) attrs = xml_obj.attributes attrs.inject({}) { |h, (n,v)| h[n] = v.value; h } end |