Class: Suretax::Api::Amount
- Inherits:
-
Object
- Object
- Suretax::Api::Amount
- Defined in:
- lib/suretax/api/tax_amount.rb
Instance Attribute Summary collapse
-
#divisor ⇒ Object
readonly
Returns the value of attribute divisor.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
Instance Method Summary collapse
- #cents ⇒ Object
-
#initialize(amount, currency = 'US6') ⇒ Amount
constructor
A new instance of Amount.
- #params ⇒ Object
- #to_f ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(amount, currency = 'US6') ⇒ Amount
Returns a new instance of Amount.
8 9 10 11 12 |
# 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 |
Instance Attribute Details
#divisor ⇒ Object (readonly)
Returns the value of attribute divisor.
6 7 8 |
# File 'lib/suretax/api/tax_amount.rb', line 6 def divisor @divisor end |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
6 7 8 |
# File 'lib/suretax/api/tax_amount.rb', line 6 def precision @precision end |
Instance Method Details
#cents ⇒ Object
26 27 28 |
# File 'lib/suretax/api/tax_amount.rb', line 26 def cents (("%.2f" % to_f).to_f * 100 ).to_i end |
#params ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/suretax/api/tax_amount.rb', line 30 def params { amount: to_i, precision: precision, divisor: divisor } end |
#to_f ⇒ Object
14 15 16 |
# File 'lib/suretax/api/tax_amount.rb', line 14 def to_f @amount.to_f end |
#to_i ⇒ Object
22 23 24 |
# File 'lib/suretax/api/tax_amount.rb', line 22 def to_i @amount.cents end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/suretax/api/tax_amount.rb', line 18 def to_s @amount.to_s end |