Class: Spree::Calculator
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::Calculator
- Defined in:
- app/models/spree/calculator.rb
Direct Known Subclasses
DefaultTax, FlatPercentItemTotal, FlatRate, FlexiRate, PerItem, PriceSack
Defined Under Namespace
Classes: DefaultTax, FlatPercentItemTotal, FlatRate, FlexiRate, PerItem, 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(something = nil) ⇒ Object
This method must be overriden in concrete calculator.
- #description ⇒ Object
- #to_s ⇒ Object
Class Method Details
.calculators ⇒ Object
Returns all calculators applicable for kind of work
23 24 25 |
# File 'app/models/spree/calculator.rb', line 23 def self.calculators Rails.application.config.spree.calculators.all end |
.description ⇒ Object
overwrite to provide description for your calculators
13 14 15 |
# File 'app/models/spree/calculator.rb', line 13 def self.description "Base Caclulator" end |
.register(*klasses) ⇒ Object
19 20 |
# File 'app/models/spree/calculator.rb', line 19 def self.register(*klasses) end |
Instance Method Details
#available?(object) ⇒ Boolean
35 36 37 |
# File 'app/models/spree/calculator.rb', line 35 def available?(object) true end |
#compute(something = nil) ⇒ Object
This method must be overriden in concrete calculator.
It should return amount computed based on #calculable and/or optional parameter
8 9 10 |
# File 'app/models/spree/calculator.rb', line 8 def compute(something=nil) raise(NotImplementedError, 'please use concrete calculator') end |
#description ⇒ Object
31 32 33 |
# File 'app/models/spree/calculator.rb', line 31 def description self.class.description end |
#to_s ⇒ Object
27 28 29 |
# File 'app/models/spree/calculator.rb', line 27 def to_s self.class.name.titleize.gsub("Calculator\/", "") end |