Class: Munificent::DonatorBundleAssigner

Inherits:
Object
  • Object
show all
Defined in:
app/services/munificent/donator_bundle_assigner.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(donator:, bundle:, fund:) ⇒ DonatorBundleAssigner

Returns a new instance of DonatorBundleAssigner.



7
8
9
10
11
# File 'app/services/munificent/donator_bundle_assigner.rb', line 7

def initialize(donator:, bundle:, fund:)
  @donator = donator
  @bundle = bundle
  @fund = fund
end

Class Method Details

.assignObject



3
4
5
# File 'app/services/munificent/donator_bundle_assigner.rb', line 3

def self.assign(...)
  new(...).assign
end

Instance Method Details

#assignObject



13
14
15
16
17
18
19
20
21
22
# File 'app/services/munificent/donator_bundle_assigner.rb', line 13

def assign
  return if fund.blank? || fund.zero?

  complete_bundles, partial_bundles = donator_bundles.partition(&:complete?)

  subtract_completed_bundle_value(complete_bundles)
  attempt_to_unlock_partial_bundles(partial_bundles)

  create_bundle_and_apportion_overpayment
end