Class: Libvirt::Spec::Device::Input
- Inherits:
-
Object
- Object
- Libvirt::Spec::Device::Input
- 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
-
#bus ⇒ Object
Returns the value of attribute bus.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(xml = nil) ⇒ Input
constructor
Initializes a new input 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) ⇒ 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
#bus ⇒ Object
Returns the value of attribute bus.
11 12 13 |
# File 'lib/libvirt/spec/device/input.rb', line 11 def bus @bus end |
#type ⇒ Object
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) = { :type => type } [:bus] = bus if bus xml.input() xml.to_xml end |