class VagrantPlugins::ProviderLibvirt::Util::Xml

Attributes

xml[R]

Public Class Methods

new(xmlstr) click to toggle source
# File lib/vagrant-libvirt/util/xml.rb, line 11
def initialize(xmlstr)
  @xml = compact_content(XmlSimple.xml_in(xmlstr, {'NormaliseSpace' => 2}))
end

Public Instance Methods

==(other) click to toggle source
# File lib/vagrant-libvirt/util/xml.rb, line 19
def ==(other)
  @xml == other.xml
end
to_str() click to toggle source
# File lib/vagrant-libvirt/util/xml.rb, line 15
def to_str
  XmlSimple.xml_out(@xml)
end

Private Instance Methods

compact_content(node) click to toggle source

content elements that are empty are preserved by xml-simple and will result in the structures being considered different even if functionality the same strip any empty ones to avoid.

# File lib/vagrant-libvirt/util/xml.rb, line 28
def compact_content(node)
  if node.is_a?(Array)
    node.map! do |element|
      compact_content(element)
    end
  elsif node.is_a?(Hash)
    if node['content'] and node['content'].empty?
      node.delete('content')
    end
    node.each do |k, v|
      node[k] = compact_content(v)
    end
  else
    return node
  end
end