Module: OpenNebula::ParsePoolBase

Included in:
OpenNebula::ParsePoolSax::PoolSax
Defined in:
lib/opennebula/xml_utils.rb

Overview

vmpool, imagepool, templatepool, vnpool, documentpool

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#poolObject

Returns the value of attribute pool.



47
48
49
# File 'lib/opennebula/xml_utils.rb', line 47

def pool
  @pool
end

Instance Method Details

#characters(s) ⇒ Object



71
72
73
# File 'lib/opennebula/xml_utils.rb', line 71

def characters(s)
    @value = s
end

#clearObject



56
57
58
59
60
# File 'lib/opennebula/xml_utils.rb', line 56

def clear
    @current = 0
    @levels  = [{}]
    @pool    = Array.new
end

#end_element(name) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/opennebula/xml_utils.rb', line 75

def end_element(name)
    if @levels[@current].empty?
        @levels[@current-1][name] = @value || {}
    else
        if @levels[@current-1][name]
            @levels[@current-1][name] = [@levels[@current-1][name], @levels[@current]].flatten
        else
            @levels[@current-1][name] = @levels[@current]
        end

        @levels[@current] = Hash.new
    end

    if name == @elem_name
        @pool << @levels[0][@elem_name]

        @current   = 0
        @levels[0] = Hash.new
    else
        @current = @current -1
    end
end

#initialize(pool_name, elem_name) ⇒ Object



49
50
51
52
53
54
# File 'lib/opennebula/xml_utils.rb', line 49

def initialize (pool_name, elem_name)
    clear

    @pool_name = pool_name
    @elem_name = elem_name
end

#start_element(name, attrs = []) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/opennebula/xml_utils.rb', line 62

def start_element(name, attrs = [])
    return if name == @pool_name
    @value = nil

    @current = @current + 1

    @levels[@current] = Hash.new if @levels[@current].nil?
end