Class: Buckaruby::Amount

Inherits:
Object
  • Object
show all
Defined in:
lib/buckaruby/amount.rb

Overview

Helper for converting/formatting amounts.

Instance Method Summary collapse

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

Returns:

  • (Boolean)


12
13
14
# File 'lib/buckaruby/amount.rb', line 12

def positive?
  @amount.positive?
end

#to_dObject



16
17
18
# File 'lib/buckaruby/amount.rb', line 16

def to_d
  @amount
end

#to_sObject

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