Class: Awsum::Ec2::VolumeParser
- Defined in:
- lib/awsum/ec2/parsers/volume_parser.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(ec2) ⇒ VolumeParser
constructor
A new instance of VolumeParser.
- #result ⇒ Object
- #tag_end(tag) ⇒ Object
- #tag_start(tag, attributes) ⇒ Object
- #text(text) ⇒ Object
Methods inherited from Parser
Constructor Details
#initialize(ec2) ⇒ VolumeParser
Returns a new instance of VolumeParser.
4 5 6 7 8 9 |
# File 'lib/awsum/ec2/parsers/volume_parser.rb', line 4 def initialize(ec2) @ec2 = ec2 @volumes = [] @text = nil @stack = [] end |
Instance Method Details
#result ⇒ Object
72 73 74 |
# File 'lib/awsum/ec2/parsers/volume_parser.rb', line 72 def result @volumes end |
#tag_end(tag) ⇒ Object
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 68 69 70 |
# File 'lib/awsum/ec2/parsers/volume_parser.rb', line 36 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
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/awsum/ec2/parsers/volume_parser.rb', line 11 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
32 33 34 |
# File 'lib/awsum/ec2/parsers/volume_parser.rb', line 32 def text(text) @text << text unless @text.nil? end |