Class: Calculator::PriceSack

Inherits:
Calculator
  • Object
show all
Defined in:
app/models/calculator/price_sack.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Calculator

#available?, calculators, #description, register, #to_s

Class Method Details

.descriptionObject



6
7
8
# File 'app/models/calculator/price_sack.rb', line 6

def self.description
  I18n.t("price_sack")
end

Instance Method Details

#compute(object) ⇒ Object

as object we always get line items, as calculable we have Coupon, ShippingMethod



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/calculator/price_sack.rb', line 11

def compute(object)
  if object.is_a?(Array)
    base = object.map{ |o| o.respond_to?(:amount) ? o.amount : o.to_d }.sum
  else
    base = object.respond_to?(:amount) ? object.amount : object.to_d
  end

  if base >= self.preferred_minimal_amount
    self.preferred_normal_amount
  else
    self.preferred_discount_amount
  end
end