class Suretax::Api::Amount

Attributes

divisor[R]
precision[R]

Public Class Methods

new(amount, currency = "US6") click to toggle source
# File lib/suretax/api/tax_amount.rb, line 8
def initialize(amount, currency = "US6")
  @amount = Monetize.parse(amount, currency)
  @precision = count_significant_decimal_places
  @divisor = @amount.currency.subunit_to_unit
end

Public Instance Methods

cents() click to toggle source
# File lib/suretax/api/tax_amount.rb, line 26
def cents
  (("%.2f" % to_f).to_f * 100).to_i
end
params() click to toggle source
# File lib/suretax/api/tax_amount.rb, line 30
def params
  {
    amount: to_i,
    precision: precision,
    divisor: divisor
  }
end
to_f() click to toggle source
# File lib/suretax/api/tax_amount.rb, line 14
def to_f
  @amount.to_f
end
to_i() click to toggle source
# File lib/suretax/api/tax_amount.rb, line 22
def to_i
  @amount.cents
end
to_s() click to toggle source
# File lib/suretax/api/tax_amount.rb, line 18
def to_s
  @amount.to_s
end

Private Instance Methods

count_significant_decimal_places() click to toggle source
# File lib/suretax/api/tax_amount.rb, line 40
def count_significant_decimal_places
  @amount.currency.subunit_to_unit.to_s.scan(/0/).count
end