class Sorare::Rewards::Tiers::QualifyPlayers

QualifyPlayers qualifies a list of sorted supply in tiers based on its rank or a provided tier Returns an array of tiers (array) containing the list of slugs for that tier

Public Instance Methods

by_rank() click to toggle source
# File lib/sorare/rewards/interactors/tiers/qualify_players.rb, line 61
def by_rank
  @by_rank ||= sorted_supply.values.first&.dig('tier').nil?
end
call() click to toggle source
# File lib/sorare/rewards/interactors/tiers/qualify_players.rb, line 15
def call
  context.players = by_rank ? qualified_players_by_rank : qualified_players_by_tier
end
nb_of_tiers() click to toggle source
# File lib/sorare/rewards/interactors/tiers/qualify_players.rb, line 39
def nb_of_tiers
  @nb_of_tiers ||= begin
    default = Sorare::Rewards.configuration.tiers
    default -= 1 while (default**2 - 1) > sorted_supply.keys.length

    default
  end
end
qualified_players_by_rank() click to toggle source

Use the rank in the array

# File lib/sorare/rewards/interactors/tiers/qualify_players.rb, line 29
def qualified_players_by_rank
  nb_of_tiers.times.map do |tier|
    sorted_supply.keys[tier_index(tier)..tier_index(tier + 1) - 1]
  end
end
qualified_players_by_tier() click to toggle source

Use the tier specified within the data

# File lib/sorare/rewards/interactors/tiers/qualify_players.rb, line 20
def qualified_players_by_tier
  Sorare::Rewards.configuration.tiers.times.map do |tier|
    sorted_supply.keys.filter do |slug|
      sorted_supply.dig(slug, 'tier') == tier
    end
  end
end
tier_depth() click to toggle source
# File lib/sorare/rewards/interactors/tiers/qualify_players.rb, line 35
def tier_depth
  @tier_depth ||= sorted_supply.keys.length / (nb_of_tiers**2 - 1)
end
tier_index(tier) click to toggle source
# File lib/sorare/rewards/interactors/tiers/qualify_players.rb, line 48
def tier_index(tier)
  return 0 unless tier.positive?
  return sorted_supply.keys.length if tier == nb_of_tiers

  tier_index(tier - 1) + tier_depth * tier_size(tier - 1)
end
tier_size(tier) click to toggle source
# File lib/sorare/rewards/interactors/tiers/qualify_players.rb, line 55
def tier_size(tier)
  return 1 unless tier.positive?

  tier_size(tier - 1) * 2
end