Class: Lutaml::Model::XmlAdapter::NokogiriDocument

Inherits:
Document
  • Object
show all
Defined in:
lib/lutaml/model/xml_adapter/nokogiri_adapter.rb

Instance Attribute Summary

Attributes inherited from Document

#root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Document

#build_attributes, #children, #declaration, #initialize, #namespace_attributes

Constructor Details

This class inherits a constructor from Lutaml::Model::XmlAdapter::Document

Class Method Details

.parse(xml) ⇒ Object



9
10
11
12
13
# File 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb', line 9

def self.parse(xml)
  parsed = Nokogiri::XML(xml)
  root = NokogiriElement.new(parsed.root)
  new(root)
end

Instance Method Details

#to_hObject



15
16
17
18
# File 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb', line 15

def to_h
  # { @root.name => parse_element(@root) }
  parse_element(@root)
end

#to_xml(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb', line 20

def to_xml(options = {})
  builder = Nokogiri::XML::Builder.new do |xml|
    build_element(xml, @root, options)
  end

  xml_options = {}
  xml_options[:indent] = 2 if options[:pretty]

  xml_data = builder.doc.root.to_xml(xml_options)
  options[:declaration] ? declaration(options) + xml_data : xml_data
end