Class: Awsum::Ec2::InstanceParser
- Defined in:
- lib/awsum/ec2/parsers/instance_parser.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(ec2) ⇒ InstanceParser
constructor
A new instance of InstanceParser.
- #result ⇒ Object
- #tag_end(tag) ⇒ Object
- #tag_start(tag, attributes) ⇒ Object
- #text(text) ⇒ Object
Methods inherited from Parser
Constructor Details
#initialize(ec2) ⇒ InstanceParser
Returns a new instance of InstanceParser.
4 5 6 7 8 9 10 11 |
# File 'lib/awsum/ec2/parsers/instance_parser.rb', line 4 def initialize(ec2) @ec2 = ec2 @instances = [] @text = nil @stack = [] @placement = nil @state = nil end |
Instance Method Details
#result ⇒ Object
94 95 96 |
# File 'lib/awsum/ec2/parsers/instance_parser.rb', line 94 def result @instances end |
#tag_end(tag) ⇒ Object
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/awsum/ec2/parsers/instance_parser.rb', line 38 def tag_end(tag) case tag when 'DescribeInstancesResponse', 'requestId', 'reservationId' #no-op when 'reservationSet', 'instancesSet', 'productCodes', 'instanceState', 'placement', 'blockDeviceMapping', 'tagSet' @stack.pop when 'item' case @stack[-1] when 'instancesSet' @instances << Instance.new( @ec2, @current['instanceId'], @current['imageId'], @current['instanceType'], State.new(@state[:code], @state[:name]), @current['dnsName'], @current['privateDnsName'], @current['keyName'], @current['kernalId'], Time.parse(@current['launchTime']), @placement, @product_codes || [], @current['ramdisk_id'], @current['reason'], @current['amiLaunchIndex'].to_i ) end when 'productCode' @product_codes << @text.strip when 'availabilityZone' @placement = @text.strip when 'code' @state[:code] = @text.strip.to_i if @stack[-1] == 'instanceState' when 'name' @state[:name] = @text.strip if @stack[-1] == 'instanceState' else case @stack[-1] when 'blockDeviceMapping' unless @text.nil? || @blockDeviceMapping.nil? text = @text.strip @blockDeviceMapping[tag] = (text == '' ? nil : text) end when 'tagSet' unless @text.nil? || @blockDeviceMapping.nil? text = @text.strip @blockDeviceMapping[tag] = (text == '' ? nil : text) end else unless @text.nil? || @current.nil? text = @text.strip @current[tag] = (text == '' ? nil : text) end end end end |
#tag_start(tag, attributes) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/awsum/ec2/parsers/instance_parser.rb', line 13 def tag_start(tag, attributes) case tag when 'reservationSet', 'instancesSet', 'productCodes', 'instanceState', 'blockDeviceMapping', 'tagSet', 'placement' @stack << tag when 'item' case @stack[-1] when 'reservationSet' when 'instancesSet' @current = {} @state = {} when 'productCodes' @product_codes = [] when 'blockDeviceMapping' @blockDeviceMapping = {} when 'tagSet' @tagSet = {} end end @text = '' end |
#text(text) ⇒ Object
34 35 36 |
# File 'lib/awsum/ec2/parsers/instance_parser.rb', line 34 def text(text) @text << text unless @text.nil? end |