Class: MagicMoney
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
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#currency ⇒ Object
Returns the value of attribute currency.
Instance Method Summary collapse
- #convert_to(new_currency) ⇒ Object
-
#initialize(amount, currency) ⇒ MagicMoney
constructor
A new instance of MagicMoney.
- #inspect ⇒ Object
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
#amount ⇒ Object
Returns the value of attribute amount.
6 7 8 |
# File 'lib/magic_money.rb', line 6 def amount @amount end |
#currency ⇒ Object
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 |
#inspect ⇒ Object
18 19 20 |
# File 'lib/magic_money.rb', line 18 def inspect "#{ amount_as_money } #{ @currency }" end |