Sha256: 610483589d8efa49660a1d2f043b9e11eec03fc69a7b0dba23da9ea5480a6aa7

Contents?: true

Size: 675 Bytes

Versions: 1

Compression:

Stored size: 675 Bytes

Contents

module Hatsrank
  class Listing
    attr_accessor :listing_id, :price, :currency, :item

    def money
      ::Money.new(price, currency_symbol)
    end

    def usd
      money.exchange_to(:USD)
    end

    class UnknownCurrencyException < Exception
      def initialize(currency)
        @currency = currency
      end
      def message
        "Currency #{@currency} not found"
      end
    end

    private
    def currency_symbol
      case currency.to_i
      when 2001
        'USD'
      when 2002
        'GBP'
      when 2003
        'EUR'
      when 2005
        'RUB'
      else
        raise UnknownCurrencyException.new(currency)
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hatsrank-0.0.1 lib/hatsrank/listing.rb