Class: Coupon::Calculator::Builder
- Inherits:
-
Object
- Object
- Coupon::Calculator::Builder
- Defined in:
- app/services/coupon/calculator/builder.rb
Overview
Base class of the discount calculator system, inherited by specialized calculation
Also serves as a calculator factory passing a coupon to the create method
Class Method Summary collapse
-
.create_calculator(calculation_type, extractor, options) ⇒ Object
Instantiate a calculator based on the calculation type, extract and tax class, also options must be specified depending on the coupon calculation type: :percentage_off :flat_amount.
Class Method Details
.create_calculator(calculation_type, extractor, options) ⇒ Object
Instantiate a calculator based on the calculation type, extract and tax class, also options
must be specified depending on the coupon calculation type:
:percentage_off
:flat_amount
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/coupon/calculator/builder.rb', line 10 def self.create_calculator(calculation_type, extractor, ) case calculation_type when '%' Coupon::Calculator::PercentageOff.new(extractor, { percentage_off: [:percentage_off] } ) when '%M' Coupon::Calculator::PercentageOff.new(extractor, { percentage_off: [:percentage_off], msrp: true } ) when '%V' Coupon::Calculator::PercentageOff.new(extractor, { percentage_off: [:percentage_off], price_with_vat: true } ) when '%1' Coupon::Calculator::PercentageOffPerQtyMet.new(extractor, percentage_off: [:percentage_off] ) when '$' Coupon::Calculator::FlatAmountOff.new(extractor, { flat_amount: [:flat_amount] } ) when '$1' Coupon::Calculator::FlatAmountOffPerUnit.new(extractor, { flat_amount: [:flat_amount] } ) when 'DP' Coupon::Calculator::ForceDiscountUnitPrice.new(extractor, { unit_price: [:flat_amount] } ) when 'MP' Coupon::Calculator::ForceMsrpUnitPrice.new(extractor, { unit_price: [:flat_amount] } ) when '?' Coupon::Calculator::AdjustableAmount.new(extractor) when '+?' Coupon::Calculator::AdjustableAmount.new(extractor, { method: :add } ) when '-?' Coupon::Calculator::AdjustableAmount.new(extractor, { method: :subtract } ) when 'SF' Coupon::Calculator::VolumePricingCalculator.new(extractor, { price_per_volume_unit: [:flat_amount], msrp: true, volume_method: :sq_ft } ) when 'LF' Coupon::Calculator::VolumePricingCalculator.new(extractor, { price_per_volume_unit: [:flat_amount], msrp: true, volume_method: :linear_ft } ) when 'SD' Coupon::Calculator::VolumePricingCalculator.new(extractor, { price_per_volume_unit: [:flat_amount], msrp: false, volume_method: :sq_ft } ) when 'LD' Coupon::Calculator::VolumePricingCalculator.new(extractor, { price_per_volume_unit: [:flat_amount], msrp: false, volume_method: :linear_ft } ) when 'MX' Coupon::Calculator::PromoMatrix.new(extractor) end end |