Class: Spree::Calculator::TieredPercent

Inherits:
Spree::Calculator show all
Defined in:
app/models/spree/calculator/tiered_percent.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spree::Calculator

#available?, calculators, #description, #to_s

Methods inherited from Base

page, spree_base_scopes

Methods included from Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Class Method Details

.descriptionObject



21
22
23
# File 'app/models/spree/calculator/tiered_percent.rb', line 21

def self.description
  Spree.t(:tiered_percent)
end

Instance Method Details

#compute(object) ⇒ Object



25
26
27
28
# File 'app/models/spree/calculator/tiered_percent.rb', line 25

def compute(object)
  base, percent = preferred_tiers.sort.reverse.detect{ |b,_| object.amount >= b }
  (object.amount * (percent || preferred_base_percent) / 100).round(2)
end