Class: Calculator::WeightBucket

Inherits:
Advanced
  • Object
show all
Defined in:
app/models/calculator/weight_bucket.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descriptionObject



4
5
6
# File 'app/models/calculator/weight_bucket.rb', line 4

def self.description
  I18n.t("weight_bucket", :scope => :calculator_names)
end

.unitObject



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