Class: Awsum::Ec2::ReservedInstanceParser

Inherits:
Parser show all
Defined in:
lib/awsum/ec2/parsers/reserved_instance_parser.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Parser

#parse, #xmldecl

Constructor Details

#initialize(ec2) ⇒ ReservedInstanceParser

Returns a new instance of ReservedInstanceParser.



4
5
6
7
8
9
# File 'lib/awsum/ec2/parsers/reserved_instance_parser.rb', line 4

def initialize(ec2)
  @ec2 = ec2
  @reserved_instances = []
  @text = nil
  @stack = []
end

Instance Method Details

#resultObject



59
60
61
# File 'lib/awsum/ec2/parsers/reserved_instance_parser.rb', line 59

def result
  @reserved_instances
end

#tag_end(tag) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/awsum/ec2/parsers/reserved_instance_parser.rb', line 28

def tag_end(tag)
  case tag
    when 'requestId'
      #no-op
    when 'reservedInstancesSet'
      @stack.pop
    when 'item'
      case @stack[-1]
        when 'reservedInstancesSet'
          @reserved_instances << ReservedInstance.new(
                                   @ec2,
                                   @current['reservedInstancesId'],
                                   @current['instanceType'],
                                   @current['availabilityZone'],
                                   Time.parse(@current['start']),
                                   @current['duration'].to_i,
                                   @current['fixedPrice'].to_f,
                                   @current['usagePrice'].to_f,
                                   @current['instanceCount'].to_i,
                                   @current['productDescription'],
                                   @current['state']
                                 )
      end
    else
      unless @text.nil? || @current.nil?
        text = @text.strip
        @current[tag] = (text == '' ? nil : text)
      end
  end
end

#tag_start(tag, attributes) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/awsum/ec2/parsers/reserved_instance_parser.rb', line 11

def tag_start(tag, attributes)
  case tag
    when 'reservedInstancesSet'
      @stack << 'reservedInstancesSet'
    when 'item'
      case @stack[-1]
        when 'reservedInstancesSet'
          @current = {}
      end
  end
  @text = ''
end

#text(text) ⇒ Object



24
25
26
# File 'lib/awsum/ec2/parsers/reserved_instance_parser.rb', line 24

def text(text)
  @text << text unless @text.nil?
end