Class: Libvirt::Spec::Domain::Clock

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

Overview

Time keeping configuration for a domain.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#raise_if_unparseables, #try

Constructor Details

#initialize(xml = nil) ⇒ Clock

Initializes a clock specification. This should never be called directly. Instead, use a Libvirt::Spec::Domain spec, which contains a clock attribute.



13
14
15
# File 'lib/libvirt/spec/domain/clock.rb', line 13

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

Instance Attribute Details

#offsetObject

Returns the value of attribute offset.



8
9
10
# File 'lib/libvirt/spec/domain/clock.rb', line 8

def offset
  @offset
end

Instance Method Details

#load!(root) ⇒ Object

Loads clock information from the given XML string. This shouldn't be called directly, since the domain spec automatically calls this.



20
21
22
23
24
# File 'lib/libvirt/spec/domain/clock.rb', line 20

def load!(root)
  root = Nokogiri::XML(root).root if !root.is_a?(Nokogiri::XML::Element)
  try(root.xpath("//clock[@offset]"), :preserve => true) { |result| self.offset = result["offset"].to_sym }
  raise_if_unparseables(root.xpath("//clock/*"))
end

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



26
27
28
29
30
31
# File 'lib/libvirt/spec/domain/clock.rb', line 26

def to_xml(parent=Nokogiri::XML::Builder.new)
  return if !offset

  parent.clock :offset => offset
  parent.to_xml
end