Class: Calculator::QuantityBucket

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descriptionObject



2
3
4
# File 'app/models/calculator/quantity_bucket.rb', line 2

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

.unitObject



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

def self.unit
  I18n.t(:qty)
end

Instance Method Details

#compute(object) ⇒ Object

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



11
12
13
14
# File 'app/models/calculator/quantity_bucket.rb', line 11

def compute(object)
  total_quantity = object.line_items.map(&:quantity).sum
  get_rate(total_quantity) || self.preferred_default_amount
end