Class: Calculator::FlatPercentItemTotal

Inherits:
Calculator
  • Object
show all
Defined in:
app/models/calculator/flat_percent_item_total.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Calculator

#available?, calculators, #description, #to_s

Class Method Details

.descriptionObject



4
5
6
# File 'app/models/calculator/flat_percent_item_total.rb', line 4

def self.description
  I18n.t("flat_percent")
end

.registerObject



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

def self.register
  super
  ShippingMethod.register_calculator(self)
end

Instance Method Details

#compute(object) ⇒ Object



13
14
15
16
17
18
# File 'app/models/calculator/flat_percent_item_total.rb', line 13

def compute(object)
  return unless object.present? and object.line_items.present?
  item_total = object.line_items.map(&:amount).sum
  value = item_total * self.preferred_flat_percent / 100.0
  (value * 100).round.to_f / 100
end