class Discounter

Attributes

composer[RW]
scope[RW]

Public Class Methods

new(composer, scope) click to toggle source
# File lib/tax_girl/discounter.rb, line 4
def initialize(composer, scope)
  @composer          = composer
  @scope             = scope
  @currency_demand   = composer.demand_methods[:discount][:currency]
  @percentage_demand = composer.demand_methods[:discount][:percentage]

  calculate_amount if @currency_demand.any?
end

Public Instance Methods

calculate_amount() click to toggle source
# File lib/tax_girl/discounter.rb, line 13
def calculate_amount
  calculate_currency
  calculate_percentage
end
calculate_currency() click to toggle source
# File lib/tax_girl/discounter.rb, line 18
def calculate_currency
  self.composer.total -= @currency_demand.map do |method|
    scope.send(method) || 0
  end.reduce(:+)
end
calculate_percentage() click to toggle source
# File lib/tax_girl/discounter.rb, line 24
def calculate_percentage
  @percentage_demand.each do |method|
    value = scope.send(method) || 0
    self.composer.total -= (value.to_f / 100) * composer.total
  end
end