Sha256: 4218f6f0930acba57d22889bb4251a19c77e0b46c77c27a1164808a0097ce46c
Contents?: true
Size: 1.53 KB
Versions: 5
Compression:
Stored size: 1.53 KB
Contents
module Awsum class Ec2 class AddressParser < Awsum::Parser #:nodoc: def initialize(ec2) @ec2 = ec2 @addresses = [] @text = nil @stack = [] end def tag_start(tag, attributes) #Quick hack so we can use the same parser for AllocateAddress which doesn't use the item tag to wrap the address information if tag == 'AllocateAddressResponse' @stack << 'addressesSet' end case tag when 'addressesSet' @stack << 'addressesSet' when 'item', 'AllocateAddressResponse' case @stack[-1] when 'addressesSet' @current = {} end end @text = '' end def text(text) @text << text unless @text.nil? end def tag_end(tag) case tag when 'DescribeAddressesResponse' #no-op when 'addressesSet' @stack.pop when 'item', 'AllocateAddressResponse' case @stack[-1] when 'addressesSet' @addresses << Address.new( @ec2, @current['publicIp'], @current['instanceId'] ) end else unless @text.nil? || @current.nil? text = @text.strip @current[tag] = (text == '' ? nil : text) end end end def result @addresses end end end end
Version data entries
5 entries across 5 versions & 1 rubygems