Sha256: 03874f2eca0e7aee081344327645679beb4170498e9375ec59fe2729a8a702d7

Contents?: true

Size: 1.92 KB

Versions: 5

Compression:

Stored size: 1.92 KB

Contents

module Awsum
  class Ec2
    class ReservedInstanceParser < Awsum::Parser #:nodoc:
      def initialize(ec2)
        @ec2 = ec2
        @reserved_instances = []
        @text = nil
        @stack = []
      end

      def tag_start(tag, attributes)
        case tag
          when 'reservedInstancesSet'
            @stack << 'reservedInstancesSet'
          when 'item'
            case @stack[-1]
              when 'reservedInstancesSet'
                @current = {}
            end
        end
        @text = ''
      end

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

      def tag_end(tag)
        case tag
          when 'requestId'
            #no-op
          when 'reservedInstancesSet'
            @stack.pop
          when 'item'
            case @stack[-1]
              when 'reservedInstancesSet'
                @reserved_instances << ReservedInstance.new(
                                         @ec2,
                                         @current['reservedInstancesId'],
                                         @current['instanceType'],
                                         @current['availabilityZone'],
                                         Time.parse(@current['start']),
                                         @current['duration'].to_i,
                                         @current['fixedPrice'].to_f,
                                         @current['usagePrice'].to_f,
                                         @current['instanceCount'].to_i,
                                         @current['productDescription'],
                                         @current['state']
                                       )
            end
          else
            unless @text.nil? || @current.nil?
              text = @text.strip
              @current[tag] = (text == '' ? nil : text)
            end
        end
      end

      def result
        @reserved_instances
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
awsum-0.5.4 lib/awsum/ec2/parsers/reserved_instance_parser.rb
awsum-0.5.3 lib/awsum/ec2/parsers/reserved_instance_parser.rb
awsum-0.5.2 lib/awsum/ec2/parsers/reserved_instance_parser.rb
awsum-0.5.1 lib/awsum/ec2/parsers/reserved_instance_parser.rb
awsum-0.5 lib/awsum/ec2/parsers/reserved_instance_parser.rb