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
6 7 8 |
# File 'app/services/coupon/calculator/flat_amount_off.rb', line 6 def initialize(line_item_extractor, = {}) super(line_item_extractor, ) end |
Instance Method Details
#calculate(discount) ⇒ Object
10 11 12 13 14 15 |
# File 'app/services/coupon/calculator/flat_amount_off.rb', line 10 def calculate(discount) raise ":flat_amount option not specified" unless @options[:flat_amount].present? 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 |