21 lines
489 B
Ruby
21 lines
489 B
Ruby
module PlanetExpressExpress
|
|
class DiscountBudget
|
|
def initialize(limit_per_month)
|
|
@limit_per_month = limit_per_month
|
|
end
|
|
|
|
def limit_discounts(shipments)
|
|
shipments[:all].each do |month|
|
|
available_budget = @limit_per_month
|
|
|
|
month.each do |shipment|
|
|
if shipment.discount > available_budget
|
|
shipment.discount = available_budget
|
|
end
|
|
available_budget -= shipment.discount
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|