Class: Coupon::Calculator::Base
- Inherits:
-
Object
- Object
- Coupon::Calculator::Base
- Defined in:
- app/services/coupon/calculator/base.rb
Overview
Service object: base.
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.
6 7 8 9 10 11 12 |
# File 'app/services/coupon/calculator/base.rb', line 6 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.
4 5 6 |
# File 'app/services/coupon/calculator/base.rb', line 4 def line_item_extractor @line_item_extractor end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'app/services/coupon/calculator/base.rb', line 4 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'app/services/coupon/calculator/base.rb', line 4 def @options end |
#tax_class ⇒ Object (readonly)
Returns the value of attribute tax_class.
4 5 6 |
# File 'app/services/coupon/calculator/base.rb', line 4 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
23 24 25 |
# File 'app/services/coupon/calculator/base.rb', line 23 def allocate_to_line(line_item, discount, allocated_amount) Coupon::LineItemDiscountAllocator.new(line_item).allocate(discount, allocated_amount) end |
#calculate(_discount) ⇒ Object
14 15 16 |
# File 'app/services/coupon/calculator/base.rb', line 14 def calculate(_discount) raise "Not Implemented" end |