Class: Libvirt::Spec::Device::Sound

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/libvirt/spec/device/sound.rb

Overview

Represents a sound device.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#raise_if_unparseables, #try

Constructor Details

#initialize(xml = nil) ⇒ Sound

Initializes a new sound device. If an XML string is given, it will be used to attempt to initialize the attributes.



12
13
14
# File 'lib/libvirt/spec/device/sound.rb', line 12

def initialize(xml=nil)
  load!(xml) if xml
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



8
9
10
# File 'lib/libvirt/spec/device/sound.rb', line 8

def model
  @model
end

Instance Method Details

#load!(xml) ⇒ Object

Attempts to initialize object attributes based on the XML string given.



18
19
20
21
22
# File 'lib/libvirt/spec/device/sound.rb', line 18

def load!(xml)
  xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
  try(xml.xpath("//sound[@model]"), :preserve => true) { |result| self.model = result["model"].to_sym }
  raise_if_unparseables(xml.xpath("//sound/*"))
end

#to_xml(xml = Nokogiri::XML::Builder.new) ⇒ Object

Returns the XML representation of this device.



25
26
27
28
# File 'lib/libvirt/spec/device/sound.rb', line 25

def to_xml(xml=Nokogiri::XML::Builder.new)
  xml.sound(:model => model)
  xml.to_xml
end