Class: Checkout

Inherits:
Object
  • Object
show all
Defined in:
lib/wunder/checkout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(promotional_rules) ⇒ Checkout

Returns a new instance of Checkout.



7
8
9
10
# File 'lib/wunder/checkout.rb', line 7

def initialize(promotional_rules)
  @basket = Basket.new
  @promotional_rules = promotional_rules
end

Instance Attribute Details

#adjustmentObject

Returns the value of attribute adjustment.



5
6
7
# File 'lib/wunder/checkout.rb', line 5

def adjustment
  @adjustment
end

#basketObject

Returns the value of attribute basket.



5
6
7
# File 'lib/wunder/checkout.rb', line 5

def basket
  @basket
end

#promotional_rulesObject

Returns the value of attribute promotional_rules.



5
6
7
# File 'lib/wunder/checkout.rb', line 5

def promotional_rules
  @promotional_rules
end

Instance Method Details

#applied_promotional_rulesObject



25
26
27
# File 'lib/wunder/checkout.rb', line 25

def applied_promotional_rules
  adjustment.eligible_promotional_rules if adjustment
end

#remove_scan(product) ⇒ Object



16
17
18
# File 'lib/wunder/checkout.rb', line 16

def remove_scan(product)
  basket.remove_item(product)
end

#scan(product) ⇒ Object



12
13
14
# File 'lib/wunder/checkout.rb', line 12

def scan(product)
  basket.add_item(product)
end

#totalObject



20
21
22
23
# File 'lib/wunder/checkout.rb', line 20

def total
  @adjustment = Adjustment.new(basket, promotional_rules)
  @adjustment.calculate_total
end