Class: Calculator::WeightBucket
- Inherits:
-
Advanced
- Object
- Advanced
- Calculator::WeightBucket
- Defined in:
- app/models/calculator/weight_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.
Class Method Details
.description ⇒ Object
4 5 6 |
# File 'app/models/calculator/weight_bucket.rb', line 4 def self.description I18n.t("weight_bucket", :scope => :calculator_names) end |
.unit ⇒ Object
8 9 10 |
# File 'app/models/calculator/weight_bucket.rb', line 8 def self.unit I18n.t('weight_unit') end |
Instance Method Details
#compute(object) ⇒ Object
as object we always get line items, as calculable we have Coupon, ShippingMethod
13 14 15 16 17 18 19 |
# File 'app/models/calculator/weight_bucket.rb', line 13 def compute(object) total_weight = object.line_items.map{|li| (li.variant.weight || self.preferred_default_weight) * li.quantity }.sum get_rate(total_weight) || self.preferred_default_amount end |