Class: MagicMoney

Inherits:
Object
  • Object
show all
Includes:
Operators
Defined in:
lib/magic_money.rb

Constant Summary collapse

RATES =
{ 'EUR' => { 'USD' => 1.11, 'Bitcoin' => 0.0047 },
'USD' => { 'EUR' => 0.9009, 'Bitcoin' => 0.0042 },
'Bitcoin' => { 'EUR' => 212.7659, 'USD' => 238.0952 } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount, currency) ⇒ MagicMoney

Returns a new instance of MagicMoney.



12
13
14
15
16
# File 'lib/magic_money.rb', line 12

def initialize(amount, currency)
  validate_currency(currency)
  @amount = amount
  @currency = currency
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



6
7
8
# File 'lib/magic_money.rb', line 6

def amount
  @amount
end

#currencyObject

Returns the value of attribute currency.



6
7
8
# File 'lib/magic_money.rb', line 6

def currency
  @currency
end

Instance Method Details

#convert_to(new_currency) ⇒ Object



22
23
24
25
# File 'lib/magic_money.rb', line 22

def convert_to(new_currency)
  validate_currency(new_currency)
  MagicMoney.new(amount_in(new_currency), new_currency)
end

#inspectObject



18
19
20
# File 'lib/magic_money.rb', line 18

def inspect
  "#{ amount_as_money } #{ @currency }"
end