Class: Libvirt::Spec::Device::Graphics

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Util

#raise_if_unparseables, #try

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

#displayObject

Returns the value of attribute display.



10
11
12
# File 'lib/libvirt/spec/device/graphics.rb', line 10

def display
  @display
end

#typeObject

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)
  options = { :type => type }
  options[:display] = display if display

  xml.graphics(options)
  xml.to_xml
end