Class: Spree::Calculator
- Includes:
- Preferences::Persistable
- Defined in:
- app/models/spree/calculator.rb
Direct Known Subclasses
DefaultTax, DistributedAmount, FlatPercentItemTotal, FlatRate, FlexiRate, FreeShipping, PercentOnLineItem, PercentPerItem, PriceSack, TieredFlatRate, TieredPercent, ReturnsCalculator, ShippingCalculator
Defined Under Namespace
Modules: Returns, Shipping Classes: DefaultTax, DistributedAmount, FlatPercentItemTotal, FlatRate, FlexiRate, FreeShipping, PercentOnLineItem, PercentPerItem, PriceSack, TieredFlatRate, TieredPercent
Class Method Summary collapse
-
.calculators ⇒ Object
Returns all calculators applicable for kind of work.
-
.description ⇒ String
A description for this calculator in few words.
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
display_includes, page, preference, #preferences
Methods included from Spree::Core::Permalinks
#generate_permalink, #save_permalink
Class Method Details
.calculators ⇒ Object
Returns all calculators applicable for kind of work
35 36 37 38 39 |
# File 'app/models/spree/calculator.rb', line 35 def self.calculators Spree::Deprecation.warn("Calling .calculators is deprecated. Please access through Rails.application.config.spree.calculators") Spree::Config.environment.calculators end |
.description ⇒ String
A description for this calculator in few words
28 29 30 |
# File 'app/models/spree/calculator.rb', line 28 def self.description model_name.human end |
Instance Method Details
#available?(_object) ⇒ Boolean
49 50 51 |
# File 'app/models/spree/calculator.rb', line 49 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
14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/spree/calculator.rb', line 14 def compute(computable) # Spree::LineItem -> :compute_line_item computable_name = computable.class.name.demodulize.underscore method_name = "compute_#{computable_name}".to_sym calculator_class = self.class if respond_to?(method_name) send(method_name, computable) else raise NotImplementedError, "Please implement '#{method_name}(#{computable_name})' in your calculator: #{calculator_class.name}" end end |
#description ⇒ Object
45 46 47 |
# File 'app/models/spree/calculator.rb', line 45 def description self.class.description end |
#to_s ⇒ Object
41 42 43 |
# File 'app/models/spree/calculator.rb', line 41 def to_s self.class.name.titleize.gsub("Calculator\/", "") end |