Class: Sorare::Rewards::Allocations::ComputeForLeague

Inherits:
Object
  • Object
show all
Includes:
Interactor
Defined in:
lib/sorare/rewards/interactors/allocations/compute_for_league.rb

Overview

ComputeForLeague computes the reward allocations for a league given a supply and configuration

Instance Method Summary collapse

Instance Method Details

#allocate_and_format!Object



20
21
22
23
24
25
26
27
28
# File 'lib/sorare/rewards/interactors/allocations/compute_for_league.rb', line 20

def allocate_and_format!
  each_rarity_allocation do |rarity|
    (allocations[rarity].first || {}).keys.index_with do |division|
      allocations[rarity].each_with_index.to_h do |qualified_allocations, tier|
        [Sorare::Rewards.configuration.transform_tier.call(tier), qualified_allocations[division]]
      end
    end
  end
end

#allocationsObject



34
35
36
37
38
# File 'lib/sorare/rewards/interactors/allocations/compute_for_league.rb', line 34

def allocations
  @allocations ||= (config || {}).keys.index_with do |rarity|
    ComputeForRarity.call!(**context.to_h, supply: supply[rarity], config: config[rarity]).rarity_allocations
  end
end

#callObject



16
17
18
# File 'lib/sorare/rewards/interactors/allocations/compute_for_league.rb', line 16

def call
  context.league_allocations = allocate_and_format!
end

#each_rarity_allocation(&block) ⇒ Object



30
31
32
# File 'lib/sorare/rewards/interactors/allocations/compute_for_league.rb', line 30

def each_rarity_allocation(&block)
  allocations.keys.index_with(&block)
end