Class: Calculator::PriceBucket
- Inherits:
-
Calculator
- Object
- ActiveRecord::Base
- Calculator
- Calculator::PriceBucket
- Defined in:
- app/models/calculator/price_bucket.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#compute(object) ⇒ Object
as object we always get line items, as calculable we have Coupon, ShippingMethod.
Methods inherited from Calculator
#available?, calculators, #description, #to_s
Class Method Details
.description ⇒ Object
6 7 8 |
# File 'app/models/calculator/price_bucket.rb', line 6 def self.description I18n.t("price_bucket") end |
.register ⇒ Object
10 11 12 13 14 |
# File 'app/models/calculator/price_bucket.rb', line 10 def self.register super #Promotion.register_calculator(self) ShippingMethod.register_calculator(self) end |
Instance Method Details
#compute(object) ⇒ Object
as object we always get line items, as calculable we have Coupon, ShippingMethod
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/calculator/price_bucket.rb', line 17 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 |