Class: Ovirt::Statistic

Inherits:
Base
  • Object
show all
Defined in:
lib/ovirt/statistic.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #operations, #relationships, #service

Class Method Summary collapse

Methods inherited from Base

#[], all, all_xml_objects, api_endpoint, #api_endpoint, #class_suffix, create_from_xml, #destroy, element_name, element_names, find_by_href, find_by_id, find_by_name, hash_from_id_and_href, href_from_creation_status_link, href_to_guid, #initialize, #keys, #method_missing, object_to_id, #operation, parse_attribute, parse_boolean, parse_first_node, parse_first_node_with_hash, parse_first_text, #reload, #replace, set_value, top_level_booleans, top_level_booleans=, top_level_integers, top_level_integers=, top_level_objects, top_level_objects=, top_level_strings, top_level_strings=, top_level_timestamps, top_level_timestamps=, #update, #update!, xml_to_actions, xml_to_hash, xml_to_nokogiri, xml_to_relationships

Constructor Details

This class inherits a constructor from Ovirt::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ovirt::Base

Class Method Details

.parse_xml(xml) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ovirt/statistic.rb', line 6

def self.parse_xml(xml)
  node, hash = xml_to_hash(xml)

  values               = []
  values_node          = node.xpath('values').first
  values_type          = values_node['type']
  values = values_node.xpath('value').collect do |v|
    datum = v.xpath('datum').text
    case values_type
    when 'INTEGER'
      datum = datum.to_i
    when 'DECIMAL'
      datum = datum.to_f
    else
      raise "unknown Values TYPE of <#{values_type}>"
    end
    datum
  end
  hash[:values]        = values

  [:vm, :nic, :disk].each do |type|
    parent_node = node.xpath(type.to_s).first
    next if parent_node.nil?
    parent = hash_from_id_and_href(parent_node)
    parent[:type] = type
    hash[:parent] = parent
  end

  hash
end