Class: Awsum::Ec2::VolumeParser

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

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Parser

#parse, #xmldecl

Constructor Details

#initialize(ec2) ⇒ VolumeParser

Returns a new instance of VolumeParser.



64
65
66
67
68
69
# File 'lib/ec2/volume.rb', line 64

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

Instance Method Details

#resultObject



132
133
134
# File 'lib/ec2/volume.rb', line 132

def result
  @volumes
end

#tag_end(tag) ⇒ Object



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
124
125
126
127
128
129
130
# File 'lib/ec2/volume.rb', line 96

def tag_end(tag)
  case tag
    when 'DescribeVolumesResponse'
      #no-op
    when 'volumeSet', 'attachmentSet'
      @stack.pop
    when 'item', 'CreateVolumeResponse'
      case @stack[-1]
        when 'volumeSet'
          @volumes << Volume.new(
                          @ec2,
                          @current['volumeId'], 
                          @current['instanceId'], 
                          @current['size'].to_i, 
                          @current['status'],
                          @current['createTime'].blank? ? nil :Time.parse(@current['createTime']),
                          @current['snapshotId'], 
                          @current['device'],
                          @current['attachTime'].blank? ? nil :Time.parse(@current['attachTime']),
                          @current['availabilityZone'],
                          @current['attachment_status']
                        )
      end
    else
      unless @text.nil? || @current.nil?
        text = @text.strip
        #Handle special case for attachmentSet/status
        if @stack[-1] == 'attachmentSet' && tag == 'status'
          @current['attachment_status'] = (text == '' ? nil : text)
        else
          @current[tag] = (text == '' ? nil : text)
        end
      end
  end
end

#tag_start(tag, attributes) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ec2/volume.rb', line 71

def tag_start(tag, attributes)
  #Quick hack so we can use the same parser for CreateVolume which doesn't use the item tag to wrap the volume information
  if tag == 'CreateVolumeResponse'
    @stack << 'volumeSet'
  end

  case tag
    when 'volumeSet'
      @stack << 'volumeSet'
    when 'attachmentSet'
      @stack << 'attachmentSet'
    when 'item', 'CreateVolumeResponse'
      case @stack[-1]
        when 'volumeSet'
          @current = {}
        when 'attachmentSet'
      end
  end
  @text = ''
end

#text(text) ⇒ Object



92
93
94
# File 'lib/ec2/volume.rb', line 92

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