Class: Buckaruby::Amount
- Inherits:
-
Object
- Object
- Buckaruby::Amount
- Defined in:
- lib/buckaruby/amount.rb
Overview
Helper for converting/formatting amounts.
Instance Method Summary collapse
-
#initialize(amount) ⇒ Amount
constructor
A new instance of Amount.
- #positive? ⇒ Boolean
- #to_d ⇒ Object
-
#to_s ⇒ Object
Convert the amount to a String with 2 decimals.
Constructor Details
#initialize(amount) ⇒ Amount
Returns a new instance of Amount.
8 9 10 |
# File 'lib/buckaruby/amount.rb', line 8 def initialize(amount) @amount = BigDecimal(amount.to_s) end |
Instance Method Details
#positive? ⇒ Boolean
12 13 14 |
# File 'lib/buckaruby/amount.rb', line 12 def positive? @amount.positive? end |
#to_d ⇒ Object
16 17 18 |
# File 'lib/buckaruby/amount.rb', line 16 def to_d @amount end |
#to_s ⇒ Object
Convert the amount to a String with 2 decimals.
21 22 23 |
# File 'lib/buckaruby/amount.rb', line 21 def to_s format('%.2f', @amount) end |