Sha256: bd5f52e958b87a9a468f8c03f9b0631b6998878c8f6c732e61e7c6ff493e5d31

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

require 'time'

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

      def tag_start(tag, attributes)
        case tag
          when 'reservedInstancesOfferingsSet'
            @stack << 'reservedInstancesOfferingsSet'
          when 'item'
            case @stack[-1]
              when 'reservedInstancesOfferingsSet'
                @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 'reservedInstancesOfferingsSet'
            @stack.pop
          when 'item'
            case @stack[-1]
              when 'reservedInstancesOfferingsSet'
                @offerings << ReservedInstancesOffering.new(
                                @ec2,
                                @current['reservedInstancesOfferingId'],
                                @current['instanceType'],
                                @current['availabilityZone'],
                                @current['duration'].to_i,
                                @current['fixedPrice'].to_f,
                                @current['usagePrice'].to_f,
                                @current['productDescription']
                              )
            end
          else
            unless @text.nil? || @current.nil?
              text = @text.strip
              @current[tag] = (text == '' ? nil : text)
            end
        end
      end

      def result
        @offerings
      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_instances_offering_parser.rb
awsum-0.5.3 lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb
awsum-0.5.2 lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb
awsum-0.5.1 lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb
awsum-0.5 lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb