Class: Devilicious::Money
- Inherits:
-
BigDecimal
- Object
- BigDecimal
- Devilicious::Money
- Defined in:
- lib/devilicious/money.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
Instance Method Summary collapse
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(other) ⇒ Object
- #exchange_to(new_currency) ⇒ Object
-
#initialize(amount, currency) ⇒ Money
constructor
A new instance of Money.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(amount, currency) ⇒ Money
Returns a new instance of Money.
7 8 9 10 11 |
# File 'lib/devilicious/money.rb', line 7 def initialize(amount, currency) @currency = currency super(amount) end |
Instance Attribute Details
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
5 6 7 |
# File 'lib/devilicious/money.rb', line 5 def currency @currency end |
Instance Method Details
#*(other) ⇒ Object
37 38 39 40 |
# File 'lib/devilicious/money.rb', line 37 def *(other) assert_currency! other self.class.new super, currency end |
#+(other) ⇒ Object
27 28 29 30 |
# File 'lib/devilicious/money.rb', line 27 def +(other) assert_currency! other self.class.new super, currency end |
#-(other) ⇒ Object
32 33 34 35 |
# File 'lib/devilicious/money.rb', line 32 def -(other) assert_currency! other self.class.new super, currency end |
#/(other) ⇒ Object
42 43 44 45 |
# File 'lib/devilicious/money.rb', line 42 def /(other) assert_currency! other self.class.new super, currency end |
#exchange_to(new_currency) ⇒ Object
13 14 15 16 17 |
# File 'lib/devilicious/money.rb', line 13 def exchange_to new_currency new_amount = CurrencyConverter.convert(self, currency, new_currency) self.class.new new_amount, new_currency end |
#inspect ⇒ Object
23 24 25 |
# File 'lib/devilicious/money.rb', line 23 def inspect "#<Devilicious::Money amount=#{to_s}>" end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/devilicious/money.rb', line 19 def to_s sprintf("%.#{decimal_places}f", self) << " " << currency end |