Created
July 24, 2017 02:05
-
-
Save 1Rhino/93d30449c7b5fe23eae4e4d720feec6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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