Class: Awsum::Ec2::SnapshotParser
- Defined in:
- lib/awsum/ec2/parsers/snapshot_parser.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(ec2) ⇒ SnapshotParser
constructor
A new instance of SnapshotParser.
- #result ⇒ Object
- #tag_end(tag) ⇒ Object
- #tag_start(tag, attributes) ⇒ Object
- #text(text) ⇒ Object
Methods inherited from Parser
Constructor Details
#initialize(ec2) ⇒ SnapshotParser
Returns a new instance of SnapshotParser.
4 5 6 7 8 9 |
# File 'lib/awsum/ec2/parsers/snapshot_parser.rb', line 4 def initialize(ec2) @ec2 = ec2 @snapshots = [] @text = nil @stack = [] end |
Instance Method Details
#result ⇒ Object
59 60 61 |
# File 'lib/awsum/ec2/parsers/snapshot_parser.rb', line 59 def result @snapshots 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 |
# File 'lib/awsum/ec2/parsers/snapshot_parser.rb', line 33 def tag_end(tag) case tag when 'DescribeSnapshotsResponts' #no-op when 'snapshotSet', 'tagSet' @stack.pop when 'item', 'CreateSnapshotResponse' case @stack[-1] when 'snapshotSet' @snapshots << Snapshot.new( @ec2, @current['snapshotId'], @current['volumeId'], @current['status'], @current['startTime'].blank? ? nil :Time.parse(@current['startTime']), @current['progress'] ) end else unless @text.nil? || @current.nil? text = @text.strip @current[tag] = (text == '' ? nil : 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/snapshot_parser.rb', line 11 def tag_start(tag, attributes) #Quick hack so we can use the same parser for CreateSnapshot which doesn't use the item tag to wrap the snapshot information if tag == 'CreateSnapshotResponse' @stack << 'snapshotSet' end case tag when 'snapshotSet', 'tagSet' @stack << tag when 'item', 'CreateSnapshotResponse' case @stack[-1] when 'snapshotSet' @current = {} end end @text = '' end |
#text(text) ⇒ Object
29 30 31 |
# File 'lib/awsum/ec2/parsers/snapshot_parser.rb', line 29 def text(text) @text << text unless @text.nil? end |