Class: Libvirt::Spec::Device::Input

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

Overview

Represents an input device, which is a device that allows interaction with the graphical framebuffer in the guest virtual machine.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#raise_if_unparseables, #try

Constructor Details

#initialize(xml = nil) ⇒ Input

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



15
16
17
# File 'lib/libvirt/spec/device/input.rb', line 15

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

Instance Attribute Details

#busObject

Returns the value of attribute bus.



11
12
13
# File 'lib/libvirt/spec/device/input.rb', line 11

def bus
  @bus
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#load!(xml) ⇒ Object

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



21
22
23
24
25
26
27
# File 'lib/libvirt/spec/device/input.rb', line 21

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

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

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

Returns the XML representation of this device



30
31
32
33
34
35
36
# File 'lib/libvirt/spec/device/input.rb', line 30

def to_xml(xml=Nokogiri::XML::Builder.new)
  options = { :type => type }
  options[:bus] = bus if bus

  xml.input(options)
  xml.to_xml
end