Module: Goldendocx::XmlSerializers::Ox
- Defined in:
- lib/goldendocx/xml_serializers/ox.rb
Class Method Summary collapse
- .build_document(tag, namespaces = [], ignore_namespaces = []) ⇒ Object
- .build_document_xml(tag, namespaces = [], ignore_namespaces = []) ⇒ Object
- .build_element(tag) ⇒ Object
- .build_xml(tag) ⇒ Object
- .parse(xml, paths = []) ⇒ Object
- .search(node, paths) ⇒ Object
Class Method Details
.build_document(tag, namespaces = [], ignore_namespaces = []) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/goldendocx/xml_serializers/ox.rb', line 31 def build_document(tag, namespaces = [], ignore_namespaces = []) ::Ox::Document.new(encoding: 'UTF-8', version: '1.0', standalone: 'yes').tap do |root| root << ::Ox::Element.new(tag).tap do |document| Goldendocx::NAMESPACES.slice(*namespaces).each do |key, namespace| document["xmlns:#{key}"] = namespace end document['mc:Ignorable'] = ignore_namespaces.join(' ') unless ignore_namespaces.empty? yield(document) if block_given? end end end |
.build_document_xml(tag, namespaces = [], ignore_namespaces = []) ⇒ Object
26 27 28 29 |
# File 'lib/goldendocx/xml_serializers/ox.rb', line 26 def build_document_xml(tag, namespaces = [], ignore_namespaces = [], &) xml = build_document(tag, namespaces, ignore_namespaces, &) ::Ox.dump(xml, indent: -1, with_xml: true) end |
.build_element(tag) ⇒ Object
45 46 47 48 49 |
# File 'lib/goldendocx/xml_serializers/ox.rb', line 45 def build_element(tag) ::Ox::Element.new(tag).tap do |element| yield(element) if block_given? end end |
.build_xml(tag) ⇒ Object
21 22 23 24 |
# File 'lib/goldendocx/xml_serializers/ox.rb', line 21 def build_xml(tag, &) xml = build_element(tag, &) ::Ox.dump(xml, indent: -1, with_xml: true, encoding: 'UTF-8') end |
.parse(xml, paths = []) ⇒ Object
9 10 11 12 13 |
# File 'lib/goldendocx/xml_serializers/ox.rb', line 9 def parse(xml, paths = []) xml = ::Ox.parse(xml) xml = ::Ox::Document.new.tap { |document| document << xml } unless xml.is_a?(::Ox::Document) search(xml, paths) end |
.search(node, paths) ⇒ Object
15 16 17 18 19 |
# File 'lib/goldendocx/xml_serializers/ox.rb', line 15 def search(node, paths) return node if paths.blank? node.locate(paths.join('/')) end |