Class: Sorare::Rewards::Tiers::QualifySupply

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

Overview

QualifySupply qualifies a supply sorted by rank in tiers Returns an array of supply per tier

Instance Method Summary collapse

Instance Method Details

#callObject



16
17
18
19
# File 'lib/sorare/rewards/interactors/tiers/qualify_supply.rb', line 16

def call
  context.count = sorted_supply.values.sum { |p| p['supply'] }
  context.supply = qualified_supply
end

#qualified_supplyObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/sorare/rewards/interactors/tiers/qualify_supply.rb', line 21

def qualified_supply
  return qualify! unless sorted_supply.values.first&.dig('tier')

  tiers = Array.new(Sorare::Rewards.configuration.tiers, 0)
  sorted_supply.each_value do |data|
    tiers[data['tier'].to_i] += data['supply']
  end

  tiers
end

#qualify!Object



32
33
34
35
36
# File 'lib/sorare/rewards/interactors/tiers/qualify_supply.rb', line 32

def qualify!
  QualifyPlayers.call!(sorted_supply: sorted_supply).players.map do |tier_players|
    tier_players.sum { |p| sorted_supply[p]['supply'] }
  end
end