Sha256: 98b55563b733a1d294e225c6925310c830531002b389184daa9003f1e7e38935

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'xmlsimple'

module VagrantPlugins
  module ProviderLibvirt
    module Util
      class Xml
        attr_reader :xml

        def initialize(xmlstr)
          @xml = compact_content(XmlSimple.xml_in(xmlstr, {'NormaliseSpace' => 2}))
        end

        def to_str
          XmlSimple.xml_out(@xml)
        end

        def ==(other)
          @xml == other.xml
        end

        private

        # 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.
        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
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vagrant-libvirt-0.12.2 lib/vagrant-libvirt/util/xml.rb
vagrant-libvirt-0.12.1 lib/vagrant-libvirt/util/xml.rb
vagrant-libvirt-0.12.0 lib/vagrant-libvirt/util/xml.rb
vagrant-libvirt-0.11.2 lib/vagrant-libvirt/util/xml.rb
vagrant-libvirt-0.11.1 lib/vagrant-libvirt/util/xml.rb
vagrant-libvirt-0.10.8 lib/vagrant-libvirt/util/xml.rb
vagrant-libvirt-0.10.7 lib/vagrant-libvirt/util/xml.rb
vagrant-libvirt-0.10.6 lib/vagrant-libvirt/util/xml.rb