Class: Libvirt::Spec::Device::Graphics
- Inherits:
-
Object
- Object
- Libvirt::Spec::Device::Graphics
- Includes:
- Util
- Defined in:
- lib/libvirt/spec/device/graphics.rb
Overview
Represents a graphics device, which allows for graphical interaction with the guest OS.
Instance Attribute Summary collapse
-
#display ⇒ Object
Returns the value of attribute display.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(xml = nil) ⇒ Graphics
constructor
Initializes a new graphics device.
-
#load!(xml) ⇒ Object
Attempts to initialize object attributes based on the XML string given.
-
#to_xml(xml = Nokogiri::XML::Builder.new) ⇒ Object
Returns the XML representation of this device.
Methods included from Util
Constructor Details
#initialize(xml = nil) ⇒ Graphics
Initializes a new graphics device. If an XML string is given, it will be used to attempt to initialize the attributes.
14 15 16 |
# File 'lib/libvirt/spec/device/graphics.rb', line 14 def initialize(xml=nil) load!(xml) if xml end |
Instance Attribute Details
#display ⇒ Object
Returns the value of attribute display.
10 11 12 |
# File 'lib/libvirt/spec/device/graphics.rb', line 10 def display @display end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/libvirt/spec/device/graphics.rb', line 9 def type @type end |
Instance Method Details
#load!(xml) ⇒ Object
Attempts to initialize object attributes based on the XML string given.
20 21 22 23 24 25 26 |
# File 'lib/libvirt/spec/device/graphics.rb', line 20 def load!(xml) xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element) try(xml.xpath("//graphics[@type]"), :preserve => true) { |result| self.type = result["type"].to_sym } try(xml.xpath("//graphics[@display]"), :preserve => true) { |result| self.display = result["display"] } raise_if_unparseables(xml.xpath("//graphics/*")) end |
#to_xml(xml = Nokogiri::XML::Builder.new) ⇒ Object
Returns the XML representation of this device.
29 30 31 32 33 34 35 |
# File 'lib/libvirt/spec/device/graphics.rb', line 29 def to_xml(xml=Nokogiri::XML::Builder.new) = { :type => type } [:display] = display if display xml.graphics() xml.to_xml end |