Module: AIXM::Concerns::XMLBuilder

Overview

Adds the XML builder wrapped to generate a document fragment.

Instance Method Summary collapse

Methods included from Memoize

included, method

Instance Method Details

#build_fragment {|Nokogiri::XML::Builder| ... } ⇒ Nokogiri::XML::DocumentFragment

Build a XML document fragment.

Yields:

  • (Nokogiri::XML::Builder)

Returns:

  • (Nokogiri::XML::DocumentFragment)


12
13
14
15
16
17
18
19
# File 'lib/aixm/concerns/xml_builder.rb', line 12

def build_fragment
  Nokogiri::XML::DocumentFragment.parse('').tap do |fragment|
    Nokogiri::XML::Builder.with(fragment) do |builder|
      yield builder
    end
    fragment.elements.each { _1.add_next_sibling("\n") }   # add newline between tags on top level
  end
end

#to_uidNokogiri::XML::DocumentFragment

Returns UID fragment.

Returns:

  • (Nokogiri::XML::DocumentFragment)

    UID fragment



22
23
24
# File 'lib/aixm/concerns/xml_builder.rb', line 22

def to_uid(...)
  build_fragment { add_uid_to(_1, ...) }
end

#to_xmlString

Returns AIXM or OFMX fragment.

Returns:

  • (String)

    AIXM or OFMX fragment



28
29
30
# File 'lib/aixm/concerns/xml_builder.rb', line 28

def to_xml(...)
  build_fragment { add_to(_1, ...) }.to_xml.strip.concat("\n")
end