-
-
Save gavinballard/bc5420ff7b4c79a9c3389537c35bd08d to your computer and use it in GitHub Desktop.
Buy Set Get X% Off Campaign
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The campaign class. | |
class BuySetGetXOffCampaign | |
def initialize(selector, discount, partitioner) | |
@selector = selector | |
@discount = discount | |
@partitioner = partitioner | |
end | |
def run(cart) | |
applicable_items = cart.line_items.select do |line_item| | |
@selector.match?(line_item) | |
end | |
discounted_items = @partitioner.partition(cart, applicable_items) | |
discounted_items.each do |line_item| | |
@discount.apply(line_item) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment