Class: Libvirt::Spec::Device::VideoModel
- Inherits:
-
Object
- Object
- Libvirt::Spec::Device::VideoModel
- Includes:
- Util
- Defined in:
- lib/libvirt/spec/device/video_model.rb
Overview
Represents a model in the specific video device.
Instance Attribute Summary collapse
-
#accel2d ⇒ Object
Returns the value of attribute accel2d.
-
#accel3d ⇒ Object
Returns the value of attribute accel3d.
-
#heads ⇒ Object
Returns the value of attribute heads.
-
#type ⇒ Object
Returns the value of attribute type.
-
#vram ⇒ Object
Returns the value of attribute vram.
Instance Method Summary collapse
-
#initialize(xml = nil) ⇒ VideoModel
constructor
Initializes a new video model device.
-
#load!(xml) ⇒ Object
Attempts to initialize object attributes based on the XML strings 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) ⇒ VideoModel
Initializes a new video model device. If an XML string is given, it will be used to attempt to initialize the attributes.
16 17 18 |
# File 'lib/libvirt/spec/device/video_model.rb', line 16 def initialize(xml=nil) load!(xml) if xml end |
Instance Attribute Details
#accel2d ⇒ Object
Returns the value of attribute accel2d.
12 13 14 |
# File 'lib/libvirt/spec/device/video_model.rb', line 12 def accel2d @accel2d end |
#accel3d ⇒ Object
Returns the value of attribute accel3d.
11 12 13 |
# File 'lib/libvirt/spec/device/video_model.rb', line 11 def accel3d @accel3d end |
#heads ⇒ Object
Returns the value of attribute heads.
10 11 12 |
# File 'lib/libvirt/spec/device/video_model.rb', line 10 def heads @heads end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/libvirt/spec/device/video_model.rb', line 8 def type @type end |
#vram ⇒ Object
Returns the value of attribute vram.
9 10 11 |
# File 'lib/libvirt/spec/device/video_model.rb', line 9 def vram @vram end |
Instance Method Details
#load!(xml) ⇒ Object
Attempts to initialize object attributes based on the XML strings given.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/libvirt/spec/device/video_model.rb', line 22 def load!(xml) xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element) try(xml.xpath("//model[@type]"), :preserve => true) { |result| self.type = result["type"].to_sym } try(xml.xpath("//model[@vram]"), :preserve => true) { |result| self.vram = result["vram"] } try(xml.xpath("//model[@heads]"), :preserve => true) { |result| self.heads = result["heads"] } try(xml.xpath("//model/acceleration")) do |result| self.accel3d = result["accel3d"] == "yes" self.accel2d = result["accel2d"] == "yes" end raise_if_unparseables(xml.xpath("//model/*")) end |
#to_xml(xml = Nokogiri::XML::Builder.new) ⇒ Object
Returns the XML representation of this device.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/libvirt/spec/device/video_model.rb', line 36 def to_xml(xml=Nokogiri::XML::Builder.new) = { :type => type } [:vram] = vram if vram [:heads] = heads if heads xml.model() do |m| a3d = accel3d ? "yes" : "no" a2d = accel2d ? "yes" : "no" m.acceleration(:accel3d => a3d, :accel2d => a2d) end xml.to_xml end |