Class: Spree::Calculator
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- 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, FreeShipping, PercentOnLineItem, PercentPerItem, PriceSack, ShippingCalculator
Defined Under Namespace
Modules: Shipping Classes: DefaultTax, FlatPercentItemTotal, FlatRate, FlexiRate, FreeShipping, PercentOnLineItem, PercentPerItem, PriceSack
Class Method Summary collapse
-
.calculators ⇒ Object
Returns all calculators applicable for kind of work.
-
.description ⇒ Object
overwrite to provide description for your calculators.
- .register(*klasses) ⇒ Object
Instance Method Summary collapse
- #available?(object) ⇒ Boolean
-
#compute(computable) ⇒ Object
This method calls a compute_<computable> method.
- #description ⇒ Object
- #to_s ⇒ Object
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
21 22 23 |
# File 'app/models/spree/calculator.rb', line 21 def self.description 'Base Calculator' end |
.register(*klasses) ⇒ Object
27 28 |
# File 'app/models/spree/calculator.rb', line 27 def self.register(*klasses) 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
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/spree/calculator.rb', line 8 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 |