Class: Calculator::FlexiRate
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Calculator
#available?, calculators, #description, #to_s
Class Method Details
.available?(object) ⇒ Boolean
10
11
12
|
# File 'app/models/calculator/flexi_rate.rb', line 10
def self.available?(object)
true
end
|
.description ⇒ Object
6
7
8
|
# File 'app/models/calculator/flexi_rate.rb', line 6
def self.description
I18n.t("flexible_rate")
end
|
14
15
16
17
18
19
|
# File 'app/models/calculator/flexi_rate.rb', line 14
def self.register
super
Coupon.register_calculator(self)
ShippingMethod.register_calculator(self)
ShippingRate.register_calculator(self)
end
|
Instance Method Details
#compute(object) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/models/calculator/flexi_rate.rb', line 21
def compute(object)
sum = 0
max = self.preferred_max_items
object.length.times do |i|
if (i % max == 0) && (max > 0)
sum += self.preferred_first_item
else
sum += self.preferred_additional_item
end
end
return(sum)
end
|