Class: TaxCalculator

Inherits:
Object
  • Object
show all
Defined in:
app/models/tax_calculator.rb

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ TaxCalculator

Returns a new instance of TaxCalculator.



2
3
4
# File 'app/models/tax_calculator.rb', line 2

def initialize(order)
  @order = order
end

Instance Method Details

#taxObject

Returns tax amount in float



7
8
9
10
11
# File 'app/models/tax_calculator.rb', line 7

def tax
  amount = BigDecimal(@order.line_items_total.to_s)

  (amount * BigDecimal(tax_percentage.to_s) * BigDecimal.new("0.01")).round(2).to_f
end