Sha256: b62c88ceed5fb37bdcd209ccb7ba0970e8b40b03955ba9c6f623baa418f53ce3

Contents?: true

Size: 703 Bytes

Versions: 3

Compression:

Stored size: 703 Bytes

Contents

module Amazon
  module Associates
    class Price < ApiResult
      include Comparable
      attr_reader :cents, :currency

      xml_reader :to_s, :from => 'FormattedPrice'
      xml_reader :currency, :from => 'CurrencyCode'
      xml_reader :cents, :from => 'Amount', :as => Integer

      def initialize(str = nil, cents = nil, currency = nil)
        @to_s = str.to_s
        @cents = cents ? Integer(cents) : 0
        @currency = currency.to_s
      end

      def <=>(other)
        return nil if @currency.nil? or @cents.nil?
        return nil if @currency != other.currency

        @cents <=> other.cents
      end

      def inspect
        "#{to_s} #{currency}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
amazon-associates-0.7.2 lib/amazon-associates/types/price.rb
amazon-associates-0.7.1 lib/amazon-associates/types/price.rb
amazon-associates-0.7.0 lib/amazon-associates/types/price.rb