Class: Adjustment

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(basket, promotional_rules) ⇒ Adjustment

Returns a new instance of Adjustment.



4
5
6
7
8
9
10
# File 'lib/wunder/adjustment.rb', line 4

def initialize(basket, promotional_rules)
  @basket = basket
  @promotional_rules = promotional_rules
  @product_promotional_rules = []
  @basket_promotional_rules = []
  @applied_promotional_rules = []
end

Instance Attribute Details

#basketObject (readonly)

Returns the value of attribute basket.



2
3
4
# File 'lib/wunder/adjustment.rb', line 2

def basket
  @basket
end

#promotional_rulesObject (readonly)

Returns the value of attribute promotional_rules.



2
3
4
# File 'lib/wunder/adjustment.rb', line 2

def promotional_rules
  @promotional_rules
end

Instance Method Details

#calculate_totalObject



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

def calculate_total
  adjusted_total = apply_item_discounts
  apply_basket_discounts(adjusted_total)
end

#eligible_promotional_rulesObject



17
18
19
20
# File 'lib/wunder/adjustment.rb', line 17

def eligible_promotional_rules
  pr = (@basket_promotional_rules | @product_promotional_rules).map(&:label)
  pr.join(",")
end