Class: Calculator
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Calculator
- Defined in:
- app/models/calculator.rb
Direct Known Subclasses
FlatPercentItemTotal, FlatRate, FlexiRate, PerItem, PriceSack, SalesTax, Vat
Defined Under Namespace
Classes: FlatPercentItemTotal, FlatRate, FlexiRate, PerItem, PriceSack, SalesTax, Vat
Class Method Summary collapse
-
.calculators ⇒ Object
Returns all calculators applicable for kind of work If passed nil, will return only general calculators.
-
.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 If passed nil, will return only general calculators
29 30 31 |
# File 'app/models/calculator.rb', line 29 def self.calculators Rails.application.config.spree.calculators.all end |
.description ⇒ Object
overwrite to provide description for your calculators
12 13 14 |
# File 'app/models/calculator.rb', line 12 def self.description "Base Caclulator" end |
.register(*klasses) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'app/models/calculator.rb', line 18 def self.register(*klasses) # @@calculators.add(self) # klasses.each do |klass| # klass = klass.constantize if klass.is_a?(String) # klass.register_calculator(self) # end # self end |
Instance Method Details
#available?(object) ⇒ Boolean
41 42 43 |
# File 'app/models/calculator.rb', line 41 def available?(object) return true #should be overridden if needed 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
7 8 9 |
# File 'app/models/calculator.rb', line 7 def compute(something=nil) raise(NotImplementedError, "please use concrete calculator") end |
#description ⇒ Object
37 38 39 |
# File 'app/models/calculator.rb', line 37 def description self.class.description end |
#to_s ⇒ Object
33 34 35 |
# File 'app/models/calculator.rb', line 33 def to_s self.class.name.titleize.gsub("Calculator\/", "") end |