class SimpleMarketplace::Offer::TotalPercentageDiscountByMinValue

Public Class Methods

new(min_value, percentage) click to toggle source
# File lib/simple_marketplace/offer/total_percentage_discount_by_min_value.rb, line 5
def initialize(min_value, percentage)
  @min_value, @percentage = min_value, percentage
end

Public Instance Methods

call(items, total) click to toggle source

Applies the percentage discount if total is greater than min_value

# File lib/simple_marketplace/offer/total_percentage_discount_by_min_value.rb, line 10
def call(items, total)
  total >= @min_value ? total.mult(BigDecimal.new(100).sub(@percentage, 4), 4).div(BigDecimal.new(100), 4) : total
end