class SimpleMarketplace::Offer::ProductDiscountByAmount
Public Class Methods
new(product_code, initial_amount, new_value)
click to toggle source
# File lib/simple_marketplace/offer/product_discount_by_amount.rb, line 5 def initialize(product_code, initial_amount, new_value) @product_code, @initial_amount, @new_value = product_code, initial_amount, new_value end
Public Instance Methods
call(items, total)
click to toggle source
Verify if the product amount is the desired to change the product value
# File lib/simple_marketplace/offer/product_discount_by_amount.rb, line 10 def call(items, total) if items.count{ |product| product.code == @product_code } >= @initial_amount items.collect{|product| product.code == @product_code ? @new_value : product.price }.reduce(:+) else total end end