-
Notifications
You must be signed in to change notification settings - Fork 0
/
shop_item.rb
48 lines (36 loc) · 1 KB
/
shop_item.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true
require './tax_exempt'
require './tax_calculator'
# represents the item in the shop list
class ShopItem
attr_accessor :product_name, :quantity, :list_price
attr_reader :total_list_price, :total_price_with_taxes
def initialize(product_name, quantity = 0, list_price = 0)
@product_name = product_name
@quantity = quantity.to_i
@unit_list_price = list_price.to_f
@total_list_price = @unit_list_price * @quantity
end
def unit_sales_tax
return 0 if TaxExempt.exemptible?(self)
TaxCalculator.sales_tax(@unit_list_price)
end
def unit_import_tax
return 0 unless imported?
TaxCalculator.import_tax(@unit_list_price)
end
def sales_tax
unit_sales_tax * @quantity
end
def import_tax
unit_import_tax * @quantity
end
def final_price
calculated_price_with_taxes = @total_list_price + sales_tax + import_tax
calculated_price_with_taxes.round(2)
end
private
def imported?
@product_name.include? 'imported'
end
end