Class: Awsum::Ec2::SnapshotParser

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

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Parser

#parse, #xmldecl

Constructor Details

#initialize(ec2) ⇒ SnapshotParser

Returns a new instance of SnapshotParser.



22
23
24
25
26
27
# File 'lib/ec2/snapshot.rb', line 22

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

Instance Method Details

#resultObject



77
78
79
# File 'lib/ec2/snapshot.rb', line 77

def result
  @snapshots
end

#tag_end(tag) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ec2/snapshot.rb', line 51

def tag_end(tag)
  case tag
    when 'DescribeSnapshotsResponts'
      #no-op
    when 'snapshotSet'
      @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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ec2/snapshot.rb', line 29

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'
      @stack << 'snapshotSet'
    when 'item', 'CreateSnapshotResponse'
      case @stack[-1]
        when 'snapshotSet'
          @current = {}
      end
  end
  @text = ''
end

#text(text) ⇒ Object



47
48
49
# File 'lib/ec2/snapshot.rb', line 47

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