Class: SolidusFriendlyPromotions::FriendlyPromotionAdjuster::ChooseDiscounts

Inherits:
Object
  • Object
show all
Defined in:
app/models/solidus_friendly_promotions/friendly_promotion_adjuster/choose_discounts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(discounts) ⇒ ChooseDiscounts

Returns a new instance of ChooseDiscounts.



8
9
10
# File 'app/models/solidus_friendly_promotions/friendly_promotion_adjuster/choose_discounts.rb', line 8

def initialize(discounts)
  @discounts = discounts
end

Instance Attribute Details

#discountsObject (readonly)

Returns the value of attribute discounts.



6
7
8
# File 'app/models/solidus_friendly_promotions/friendly_promotion_adjuster/choose_discounts.rb', line 6

def discounts
  @discounts
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
# File 'app/models/solidus_friendly_promotions/friendly_promotion_adjuster/choose_discounts.rb', line 12

def call
  Array.wrap(
    discounts.min_by do |discount|
      [discount.amount, -discount.source&.id.to_i]
    end
  )
end