Module: Operations
Instance Method Summary collapse
- #*(value) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(value) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #convert_to(new_currency) ⇒ Object
- #inspect ⇒ Object
Instance Method Details
#*(value) ⇒ Object
24 25 26 |
# File 'lib/smart_money/operations.rb', line 24 def *(value) Money.new @amount*value, @currency if value.is_a?(Numeric) end |
#+(other) ⇒ Object
14 15 16 17 |
# File 'lib/smart_money/operations.rb', line 14 def +(other) raise TypeError unless other.is_a?(Money) Money.new @amount+other.convert_to(@currency).amount, @currency end |
#-(other) ⇒ Object
19 20 21 22 |
# File 'lib/smart_money/operations.rb', line 19 def -(other) raise TypeError unless other.is_a?(Money) Money.new @amount-other.convert_to(@currency).amount, @currency end |
#/(value) ⇒ Object
28 29 30 |
# File 'lib/smart_money/operations.rb', line 28 def /(value) Money.new @amount/value, @currency if value.is_a?(Numeric) end |
#<=>(other) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/smart_money/operations.rb', line 37 def <=>(other) raise TypeError unless other.is_a?(Money) if @currency != other.currency other = other.convert_to(@currency) end @amount.round(2) <=> other.amount.round(2) end |
#==(other) ⇒ Object
32 33 34 35 |
# File 'lib/smart_money/operations.rb', line 32 def ==(other) raise TypeError unless other.is_a?(Money) @amount.round(2)==other.convert_to(@currency).amount.round(2) end |
#convert_to(new_currency) ⇒ Object
5 6 7 8 |
# File 'lib/smart_money/operations.rb', line 5 def convert_to(new_currency) new_amount = Money.convert(@amount, @currency.upcase, new_currency.upcase).round(2) Money.new(new_amount, new_currency) end |
#inspect ⇒ Object
10 11 12 |
# File 'lib/smart_money/operations.rb', line 10 def inspect "#{@amount} #{@currency}" end |