Class: Calculator
- Defined in:
- app/models/calculator.rb
Direct Known Subclasses
FlatPercentItemTotal, FlatRate, FlexiRate, PerItem, PriceBucket, SalesTax, Vat
Defined Under Namespace
Classes: FlatPercentItemTotal, FlatRate, FlexiRate, PerItem, PriceBucket, SalesTax, Vat
Constant Summary collapse
- @@calculators =
Set.new
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 ⇒ Object
Registers calculator to be used with selected kinds of operations.
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
26 27 28 |
# File 'app/models/calculator.rb', line 26 def self.calculators @@calculators.to_a 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 ⇒ Object
Registers calculator to be used with selected kinds of operations
20 21 22 |
# File 'app/models/calculator.rb', line 20 def self.register @@calculators.add(self) end |
Instance Method Details
#available?(object) ⇒ Boolean
38 39 40 |
# File 'app/models/calculator.rb', line 38 def available?(object) self.class.available?(object) 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
34 35 36 |
# File 'app/models/calculator.rb', line 34 def description self.class.description end |
#to_s ⇒ Object
30 31 32 |
# File 'app/models/calculator.rb', line 30 def to_s self.class.name.titleize.gsub("Calculator\/", "") end |