Class: Adjustment
- Inherits:
-
Object
- Object
- Adjustment
- Defined in:
- lib/wunder/adjustment.rb
Instance Attribute Summary collapse
-
#basket ⇒ Object
readonly
Returns the value of attribute basket.
-
#promotional_rules ⇒ Object
readonly
Returns the value of attribute promotional_rules.
Instance Method Summary collapse
- #calculate_total ⇒ Object
- #eligible_promotional_rules ⇒ Object
-
#initialize(basket, promotional_rules) ⇒ Adjustment
constructor
A new instance of Adjustment.
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
#basket ⇒ Object (readonly)
Returns the value of attribute basket.
2 3 4 |
# File 'lib/wunder/adjustment.rb', line 2 def basket @basket end |
#promotional_rules ⇒ Object (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_total ⇒ Object
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_rules ⇒ Object
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 |