Skip to content

Instantly share code, notes, and snippets.

@1Rhino
Created July 24, 2017 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1Rhino/93d30449c7b5fe23eae4e4d720feec6d to your computer and use it in GitHub Desktop.
Save 1Rhino/93d30449c7b5fe23eae4e4d720feec6d to your computer and use it in GitHub Desktop.
module TaxServices
class ItemPrice
def initialize(total_price, has_tax, has_service_tax)
@total_price = total_price
@service_tax_rate = has_tax ? Settings.tax.service_tax_rate : 0
@tax_rate = has_service_tax ? Settings.tax.tax_rate : 0
end
def perform
OpenStruct(
item_price: item_price,
tax: tax,
service_tax: service_tax
)
end
def item_price
@item_price ||= @total_price / ((1 + @service_tax_rate) * (1 + @tax_rate))
end
def service_tax
item_price * @service_tax_rate
end
def tax
(item_price + service_tax) * @tax_rate
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment