Class: Spree::Calculator
- Defined in:
- app/models/spree/calculator.rb,
app/models/spree/calculator/percent_on_line_item.rb
Direct Known Subclasses
DefaultTax, FlatPercentItemTotal, FlatRate, FlexiRate, PercentOnLineItem, PercentPerItem, PriceSack, TieredFlatRate, TieredPercent, ReturnsCalculator, ShippingCalculator
Defined Under Namespace
Modules: Returns, Shipping Classes: DefaultTax, FlatPercentItemTotal, FlatRate, FlexiRate, PercentOnLineItem, PercentPerItem, PriceSack, TieredFlatRate, TieredPercent
Class Method Summary collapse
-
.calculators ⇒ Object
Returns all calculators applicable for kind of work.
-
.description ⇒ Object
overwrite to provide description for your calculators.
Instance Method Summary collapse
- #available?(object) ⇒ Boolean
-
#compute(computable) ⇒ Object
This method calls a compute_<computable> method.
- #description ⇒ Object
- #to_s ⇒ Object
Methods inherited from Base
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
.calculators ⇒ Object
Returns all calculators applicable for kind of work
31 32 33 |
# File 'app/models/spree/calculator.rb', line 31 def self.calculators Rails.application.config.spree.calculators end |
.description ⇒ Object
overwrite to provide description for your calculators
26 27 28 |
# File 'app/models/spree/calculator.rb', line 26 def self.description 'Base Calculator' end |
Instance Method Details
#available?(object) ⇒ Boolean
43 44 45 |
# File 'app/models/spree/calculator.rb', line 43 def available?(object) true end |
#compute(computable) ⇒ Object
This method calls a compute_<computable> method. must be overriden in concrete calculator.
It should return amount computed based on #calculable and the computable parameter
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/spree/calculator.rb', line 13 def compute(computable) # Spree::LineItem -> :compute_line_item computable_name = computable.class.name.demodulize.underscore method = "compute_#{computable_name}".to_sym calculator_class = self.class if respond_to?(method) self.send(method, computable) else raise NotImplementedError, "Please implement '#{method}(#{computable_name})' in your calculator: #{calculator_class.name}" end end |
#description ⇒ Object
39 40 41 |
# File 'app/models/spree/calculator.rb', line 39 def description self.class.description end |
#to_s ⇒ Object
35 36 37 |
# File 'app/models/spree/calculator.rb', line 35 def to_s self.class.name.titleize.gsub("Calculator\/", "") end |