Class: Coupon::Calculator::Base

Inherits:
Object
  • Object
show all
Defined in:
app/services/coupon/calculator/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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,options = {})
  @line_item_extractor = line_item_extractor
  @tax_class = @line_item_extractor.tax_class.to_s.downcase
  @logger = options[:logger] || Rails.logger
  @allocator = options[:allocator]
  @options = options
end

Instance Attribute Details

#line_item_extractorObject (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

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'app/services/coupon/calculator/base.rb', line 3

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'app/services/coupon/calculator/base.rb', line 3

def options
  @options
end

#tax_classObject (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