Class: Awsum::Ec2::ReservedInstancesOfferingParser

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

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Parser

#parse, #xmldecl

Constructor Details

#initialize(ec2) ⇒ ReservedInstancesOfferingParser

Returns a new instance of ReservedInstancesOfferingParser.



6
7
8
9
10
11
# File 'lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb', line 6

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

Instance Method Details

#resultObject



58
59
60
# File 'lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb', line 58

def result
  @offerings
end

#tag_end(tag) ⇒ Object



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
# File 'lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb', line 30

def tag_end(tag)
  case tag
    when 'requestId'
      #no-op
    when 'reservedInstancesOfferingsSet'
      @stack.pop
    when 'item'
      case @stack[-1]
        when 'reservedInstancesOfferingsSet'
          @offerings << ReservedInstancesOffering.new(
                          @ec2,
                          @current['reservedInstancesOfferingId'],
                          @current['instanceType'],
                          @current['availabilityZone'],
                          @current['duration'].to_i,
                          @current['fixedPrice'].to_f,
                          @current['usagePrice'].to_f,
                          @current['productDescription']
                        )
      end
    else
      unless @text.nil? || @current.nil?
        text = @text.strip
        @current[tag] = (text == '' ? nil : text)
      end
  end
end

#tag_start(tag, attributes) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb', line 13

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

#text(text) ⇒ Object



26
27
28
# File 'lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb', line 26

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