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



67
68
69
# File 'lib/awsum/ec2/parsers/image_parser.rb', line 67

def result
  @images
end

#tag_end(tag) ⇒ Object



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

def tag_end(tag)
  case tag
    when 'DescribeImagesResponse', 'requestId'
      #no-op
    when 'imagesSet', 'productCodes', 'blockDeviceMapping'
      @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
# File 'lib/awsum/ec2/parsers/image_parser.rb', line 11

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

#text(text) ⇒ Object



27
28
29
# File 'lib/awsum/ec2/parsers/image_parser.rb', line 27

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