Class: Sorare::Rewards::League
- Inherits:
-
Object
- Object
- Sorare::Rewards::League
- Defined in:
- lib/sorare/rewards/league.rb
Overview
League stores the reward config for a league
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#game_week ⇒ Object
readonly
Returns the value of attribute game_week.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#supply ⇒ Object
readonly
Returns the value of attribute supply.
Instance Method Summary collapse
- #cards_in_circulation_limit(rarity) ⇒ Object
- #each_division_prize_pools ⇒ Object
- #each_rarity_supply ⇒ Object
- #each_rarity_tier_supply ⇒ Object
-
#initialize(name:, config:, supply:, game_week:) ⇒ League
constructor
A new instance of League.
- #picker_of(rarity, tier, **kwargs) ⇒ Object
- #qualified_supply(rarity, tier = nil) ⇒ Object
- #rewards_ratio_per_cards_in_circulation_for_rarity(rarity) ⇒ Object
Constructor Details
#initialize(name:, config:, supply:, game_week:) ⇒ League
Returns a new instance of League.
13 14 15 16 17 18 |
# File 'lib/sorare/rewards/league.rb', line 13 def initialize(name:, config:, supply:, game_week:) @name = name @config = config @supply = supply @game_week = game_week end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/sorare/rewards/league.rb', line 9 def config @config end |
#game_week ⇒ Object (readonly)
Returns the value of attribute game_week.
9 10 11 |
# File 'lib/sorare/rewards/league.rb', line 9 def game_week @game_week end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/sorare/rewards/league.rb', line 9 def name @name end |
#supply ⇒ Object (readonly)
Returns the value of attribute supply.
9 10 11 |
# File 'lib/sorare/rewards/league.rb', line 9 def supply @supply end |
Instance Method Details
#cards_in_circulation_limit(rarity) ⇒ Object
26 27 28 29 30 |
# File 'lib/sorare/rewards/league.rb', line 26 def cards_in_circulation_limit(rarity) return unless cards_in_circulation&.dig(rarity) && rewards_ratio_per_cards_in_circulation_for_rarity(rarity) (cards_in_circulation[rarity] * rewards_ratio_per_cards_in_circulation_for_rarity(rarity)).floor end |
#each_division_prize_pools ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/sorare/rewards/league.rb', line 40 def each_division_prize_pools prize_pools.each_with_index do |prize_pool, index| return to_enum(:each_division_prize_pools) unless block_given? yield(index + 1, prize_pool) end end |
#each_rarity_supply ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/sorare/rewards/league.rb', line 48 def each_rarity_supply supply.each_key do |rarity| return to_enum(:each_rarity_supply) unless block_given? yield(rarity, supply[rarity]) end end |
#each_rarity_tier_supply ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/sorare/rewards/league.rb', line 56 def each_rarity_tier_supply each_rarity_supply do |rarity, _| qualified_supply(rarity).each do |tier, qualified_supply| return to_enum(:each_rarity_tier_supply) unless block_given? yield(rarity, tier, qualified_supply) end end end |
#picker_of(rarity, tier, **kwargs) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/sorare/rewards/league.rb', line 75 def picker_of(rarity, tier, **kwargs) scenario = kwargs.sort.to_h.to_json @pickers ||= {} @pickers[rarity] ||= {} @pickers[rarity][tier] ||= {} @pickers[rarity][tier][scenario] ||= CardPicker.new(self, rarity, tier, **kwargs) end |
#qualified_supply(rarity, tier = nil) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/sorare/rewards/league.rb', line 66 def qualified_supply(rarity, tier = nil) @qualified_supplies ||= {} @qualified_supplies[rarity] ||= Tiers::QualifyPlayers.call!(sorted_supply: supply[rarity]).players .each_with_index.to_h do |supply, supply_tier| [Sorare::Rewards.configuration.transform_tier.call(supply_tier), supply] end tier ? @qualified_supplies[rarity][tier] : @qualified_supplies[rarity] end |
#rewards_ratio_per_cards_in_circulation_for_rarity(rarity) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/sorare/rewards/league.rb', line 32 def rewards_ratio_per_cards_in_circulation_for_rarity(rarity) if game_week.config.rewards_ratio_per_cards_in_circulation.is_a?(Hash) return game_week.config.rewards_ratio_per_cards_in_circulation[rarity] end game_week.config.rewards_ratio_per_cards_in_circulation end |