class Tikkie::Api::Amount

Helper for converting amounts to cents and back.

Public Class Methods

from_cents(cents) click to toggle source
# File lib/tikkie/api/amount.rb, line 10
def from_cents(cents)
  amount = BigDecimal(cents) / 100
  new(amount)
end
new(amount) click to toggle source
# File lib/tikkie/api/amount.rb, line 16
def initialize(amount)
  @amount = BigDecimal(amount.to_s)
end

Public Instance Methods

to_cents() click to toggle source
# File lib/tikkie/api/amount.rb, line 29
def to_cents
  cents = @amount * 100
  cents.to_i
end
to_d() click to toggle source
# File lib/tikkie/api/amount.rb, line 20
def to_d
  @amount
end
to_s() click to toggle source

Convert the amount to a String with 2 decimals.

# File lib/tikkie/api/amount.rb, line 25
def to_s
  format("%.2f", @amount)
end