Class: Coupon::Calculator::Base
- Inherits:
-
Object
- Object
- Coupon::Calculator::Base
- Defined in:
- app/services/coupon/calculator/base.rb
Direct Known Subclasses
AdjustableAmount, FlatAmountOff, FlatAmountOffPerUnit, ForceDiscountUnitPrice, ForceMsrpUnitPrice, PercentageOff, PercentageOffPerQtyMet, PromoMatrix, VolumePricingCalculator
Instance Attribute Summary collapse
-
#line_item_extractor ⇒ Object
readonly
Returns the value of attribute line_item_extractor.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#tax_class ⇒ Object
readonly
Returns the value of attribute tax_class.
Instance Method Summary collapse
-
#allocate_to_line(line_item, discount, allocated_amount) ⇒ Object
Allocates a computed discount to a line line_item : instance of LineItem the line item to build discount lines upon discount : A reference to the Discount instance in use allocated_amount : The per-unit discount allocated, if its a discount, should be negative.
- #calculate(discount) ⇒ Object
-
#initialize(line_item_extractor, options = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(line_item_extractor, options = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 |
# File 'app/services/coupon/calculator/base.rb', line 5 def initialize(line_item_extractor, = {}) @line_item_extractor = line_item_extractor @tax_class = @line_item_extractor.tax_class.to_s.downcase @logger = [:logger] || Rails.logger @allocator = [:allocator] @options = end |
Instance Attribute Details
#line_item_extractor ⇒ Object (readonly)
Returns the value of attribute line_item_extractor.
3 4 5 |
# File 'app/services/coupon/calculator/base.rb', line 3 def line_item_extractor @line_item_extractor end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'app/services/coupon/calculator/base.rb', line 3 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'app/services/coupon/calculator/base.rb', line 3 def @options end |
#tax_class ⇒ Object (readonly)
Returns the value of attribute tax_class.
3 4 5 |
# File 'app/services/coupon/calculator/base.rb', line 3 def tax_class @tax_class end |
Instance Method Details
#allocate_to_line(line_item, discount, allocated_amount) ⇒ Object
Allocates a computed discount to a line
line_item : instance of LineItem the line item to build discount lines upon
discount : A reference to the Discount instance in use
allocated_amount : The per-unit discount allocated,
if its a discount, should be negative
22 23 24 |
# File 'app/services/coupon/calculator/base.rb', line 22 def allocate_to_line(line_item, discount, allocated_amount) Coupon::LineItemDiscountAllocator.new(line_item).allocate(discount, allocated_amount) end |
#calculate(discount) ⇒ Object
13 14 15 |
# File 'app/services/coupon/calculator/base.rb', line 13 def calculate(discount) raise "Not Implemented" end |