Class: Spree::Calculator

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spree/calculator.rb

Defined Under Namespace

Classes: DefaultTax, FlatPercentItemTotal, FlatRate, FlexiRate, PerItem, PriceSack

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.calculatorsObject

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

.descriptionObject

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

Returns:

  • (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

Raises:

  • (NotImplementedError)


8
9
10
# File 'app/models/spree/calculator.rb', line 8

def compute(something=nil)
  raise(NotImplementedError, 'please use concrete calculator')
end

#descriptionObject



31
32
33
# File 'app/models/spree/calculator.rb', line 31

def description
  self.class.description
end

#to_sObject



27
28
29
# File 'app/models/spree/calculator.rb', line 27

def to_s
  self.class.name.titleize.gsub("Calculator\/", "")
end