Class: Sorare::Rewards::Allocations::ComputeForRarity

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

Overview

ComputeForRarity computes the reward allocations for a rarity in a league

Instance Method Summary collapse

Instance Method Details

#allocationsObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sorare/rewards/interactors/allocations/compute_for_rarity.rb', line 22

def allocations
  return [] unless supply

  supply.each_with_index.map do |tier_supply, tier|
    ComputeForQuality.call!(
      **context.to_h,
      supply: tier_supply,
      config: tier_config(tier)
    ).quality_allocations
  end
end

#callObject



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

def call
  context.fail!(error: 'Invalid config') unless config

  context.rarity_allocations = allocations
end

#tier_config(tier) ⇒ Object



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

def tier_config(tier)
  config[Sorare::Rewards.configuration.transform_tier.call(tier)]
end