Module: Exchange::Conversability

Defined in:
lib/exchange/core_extensions/numeric/conversability.rb

Overview

The conversability module which will get included in Fixnum and Float, giving them the in currency instantiate methods

Author:

  • Beat Richartz

Since:

  • 0.1

Version:

  • 0.10

Instance Method Summary collapse

Instance Method Details

#in(currency, options = {}) ⇒ Object

The in method instantiates a money object from a numeric type.

Examples:

Instantiate from any type of number

40.in(:usd) => #<Exchange::Money @value=40 @currency=:usd>
-33.in(:nok) => #<Exchange::Money @value=-33 @currency=:nok>
33.333.in(:sek) => #<Exchange::Money @value=33.333 @currency=:sek>

Instantiate and immediatly convert

1.in(:usd).to(:eur) => #<Exchange::Money @value=0.79 @currency=:eur>
1.in(:nok).to(:chf) => #<Exchange::Money @value=6.55 @currency=:chf>
-3.5.in(:chf).to(:dkk) => #<Exchange::Money @value=-346.55 @currency=:huf>

Instantiate and immediatly convert at a specific time in the past

1.in(:usd).to(:eur, :at => Time.now - 86400) => #<Exchange::Money @value=0.80 @currency=:eur>
1.in(:nok).to(:chf, :at => Time.now - 3600) => #<Exchange::Money @value=6.57 @currency=:chf>
-3.5.in(:dkk).to(:huf, :at => Time.now - 172800) => #<Exchange::Money @value=-337.40 @currency=:huf>

Parameters:

  • currency (Symbol)

    the currency to instantiate the money with

  • options (Hash) (defaults to: {})

    The options to instantiate the currency with

  • [Time] (Hash)

    a customizable set of options

Since:

  • 0.1

Version:

  • 0.10



32
33
34
# File 'lib/exchange/core_extensions/numeric/conversability.rb', line 32

def in currency, options={}
  Money.new(self, currency, options)
end