Class: Coupon::Calculator::FlatAmountOff
- Inherits:
-
Base
- Object
- Base
- Coupon::Calculator::FlatAmountOff
- Defined in:
- app/services/coupon/calculator/flat_amount_off.rb
Overview
Classic coupon simply applying a flat amount off to all qualifying item,
one lump sum subtracted to the whole and allocated proportionally
Instance Method Summary collapse
- #calculate(discount) ⇒ Object
-
#initialize(line_item_extractor, options = {}) ⇒ FlatAmountOff
constructor
custom options required: :flat_amount, the $ amount to take off.
Constructor Details
#initialize(line_item_extractor, options = {}) ⇒ FlatAmountOff
custom options required:
:flat_amount, the $ amount to take off
7 8 9 |
# File 'app/services/coupon/calculator/flat_amount_off.rb', line 7 def initialize(line_item_extractor, = {}) super end |
Instance Method Details
#calculate(discount) ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/services/coupon/calculator/flat_amount_off.rb', line 11 def calculate(discount) raise ":flat_amount option not specified" if @options[:flat_amount].blank? base_amount = @line_item_extractor.get_base_amount_discounted allocated_amount = -[@options[:flat_amount].abs, base_amount].min Coupon::MsrpAllocator.new(@line_item_extractor).allocate(discount, allocated_amount) end |