Class: Awsum::Ec2::ImageParser

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

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Parser

#parse, #xmldecl

Constructor Details

#initialize(ec2) ⇒ ImageParser

Returns a new instance of ImageParser.



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

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

Instance Method Details

#resultObject



69
70
71
# File 'lib/awsum/ec2/parsers/image_parser.rb', line 69

def result
  @images
end

#tag_end(tag) ⇒ Object



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
58
59
60
61
62
63
64
65
66
67
# File 'lib/awsum/ec2/parsers/image_parser.rb', line 33

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/awsum/ec2/parsers/image_parser.rb', line 11

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



29
30
31
# File 'lib/awsum/ec2/parsers/image_parser.rb', line 29

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