Sha256: 6875cc85031e81e0a8030c84a9399f99e515f175163b6b44176eb751805bbb26
Contents?: true
Size: 852 Bytes
Versions: 21
Compression:
Stored size: 852 Bytes
Contents
module Spree class PromotionChooser def initialize(adjustments) @adjustments = adjustments end # Picks the best promotion from this set of adjustments, all others are # marked as ineligible. # # @return [BigDecimal] The amount of the best adjustment def update if best_promotion_adjustment @adjustments.select(&:eligible?).each do |adjustment| next if adjustment == best_promotion_adjustment adjustment.update_columns(eligible: false) end best_promotion_adjustment.amount else BigDecimal.new('0') end end # @return The best promotion from this set of adjustments. def best_promotion_adjustment @best_promotion_adjustment ||= @adjustments.select(&:eligible?).min_by do |a| [a.amount, -a.id] end end end end
Version data entries
21 entries across 21 versions & 1 rubygems