Class: Awsum::Ec2::ImageParser

Inherits:
Parser show all
Defined in:
lib/ec2/image.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Parser

#parse, #xmldecl

Constructor Details

#initialize(ec2) ⇒ ImageParser

Returns a new instance of ImageParser.



60
61
62
63
64
65
# File 'lib/ec2/image.rb', line 60

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

Instance Method Details

#resultObject



125
126
127
# File 'lib/ec2/image.rb', line 125

def result
  @images
end

#tag_end(tag) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ec2/image.rb', line 89

def tag_end(tag)
  case tag
    when 'DescribeImagesResponse', 'requestId'
      #no-op
    when 'imagesSet', 'productCodes'
      @stack.pop
    when 'item'
      case @stack[-1]
        when 'imagesSet'
          @images << Image.new(
                        @ec2,
                        @current['imageId'], 
                        @current['imageLocation'], 
                        @current['imageState'], 
                        @current['imageOwnerId'], 
                        @current['isPublic'] == 'true', 
                        @current['architecture'], 
                        @current['imageType'],
                        @current['kernelId'],
                        @current['ramdiskId'],
                        @current['platform'],
                        @product_codes || []
                      )
          @text = ''
      end
    when 'productCode'
      @product_codes << @text.strip
    else
      unless @text.nil?
        text = @text.strip
        @current[tag] = (text == '' ? nil : text)
        @text = ''
      end
  end
end

#tag_start(tag, attributes) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ec2/image.rb', line 67

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

#text(text) ⇒ Object



85
86
87
# File 'lib/ec2/image.rb', line 85

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