Class: Libvirt::Spec::Device::Video

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

Overview

Represents a video device.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#raise_if_unparseables, #try

Constructor Details

#initialize(xml = nil) ⇒ Video

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



12
13
14
15
16
# File 'lib/libvirt/spec/device/video.rb', line 12

def initialize(xml=nil)
  @models = []

  load!(xml) if xml
end

Instance Attribute Details

#modelsObject

Returns the value of attribute models.



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

def models
  @models
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
27
28
29
30
31
32
# File 'lib/libvirt/spec/device/video.rb', line 20

def load!(xml)
  xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)

  try(xml.xpath("//video/model"), :multi => true) do |result|
    self.models = []

    result.each do |model|
      self.models << VideoModel.new(model)
    end
  end

  raise_if_unparseables(xml.xpath("//video/*"))
end

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

Returns the XML representation of this device.



35
36
37
38
39
40
41
42
43
# File 'lib/libvirt/spec/device/video.rb', line 35

def to_xml(xml=Nokogiri::XML::Builder.new)
  xml.video do |v|
    models.each do |model|
      model.to_xml(xml)
    end
  end

  xml.to_xml
end