Class: Sorare::Rewards::GameWeek
- Inherits:
-
Object
- Object
- Sorare::Rewards::GameWeek
- Defined in:
- lib/sorare/rewards/game_week.rb
Overview
GameWeek stores the data of a game week
Instance Attribute Summary collapse
-
#salt ⇒ Object
readonly
Returns the value of attribute salt.
Instance Method Summary collapse
- #config ⇒ Object
- #data ⇒ Object
- #each_league ⇒ Object
-
#initialize(data: nil, hash: nil, salt: nil) ⇒ GameWeek
constructor
A new instance of GameWeek.
- #inspect ⇒ Object
- #league(name) ⇒ Object
- #loaded? ⇒ Boolean
- #player(slug) ⇒ Object
- #supply_for(league, rarity: nil, player: nil) ⇒ Object
Constructor Details
#initialize(data: nil, hash: nil, salt: nil) ⇒ GameWeek
Returns a new instance of GameWeek.
13 14 15 16 17 |
# File 'lib/sorare/rewards/game_week.rb', line 13 def initialize(data: nil, hash: nil, salt: nil) @uri = URI.parse("#{Sorare::Rewards.configuration.gateway}#{hash}") @data = data @salt = salt end |
Instance Attribute Details
#salt ⇒ Object (readonly)
Returns the value of attribute salt.
11 12 13 |
# File 'lib/sorare/rewards/game_week.rb', line 11 def salt @salt end |
Instance Method Details
#config ⇒ Object
29 30 31 |
# File 'lib/sorare/rewards/game_week.rb', line 29 def config @config ||= GameWeekConfig.new(data['config']) end |
#data ⇒ Object
25 26 27 |
# File 'lib/sorare/rewards/game_week.rb', line 25 def data @data ||= JSON.parse(@uri.open.read) end |
#each_league ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/sorare/rewards/game_week.rb', line 40 def each_league (leagues || {}).each_key do |league_name| return to_enum(:each_league) unless block_given? yield(league(league_name)) end end |
#inspect ⇒ Object
60 61 62 |
# File 'lib/sorare/rewards/game_week.rb', line 60 def inspect format('#<%<class>s %<data>s>', { class: self.class.name, data: { loaded: loaded?, hash: hash, salt: salt } }) end |
#league(name) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/sorare/rewards/game_week.rb', line 48 def league(name) raise 'Unknown league' unless (leagues || {})[name] League.new( game_week: self, name: name, config: leagues[name], supply: supply[leagues.dig(name, 'pool_supply')] ) end |
#loaded? ⇒ Boolean
64 65 66 |
# File 'lib/sorare/rewards/game_week.rb', line 64 def loaded? data.present? end |
#player(slug) ⇒ Object
56 57 58 |
# File 'lib/sorare/rewards/game_week.rb', line 56 def player(slug) Player.new(slug, self) end |
#supply_for(league, rarity: nil, player: nil) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/sorare/rewards/game_week.rb', line 33 def supply_for(league, rarity: nil, player: nil) return (supply.dig(league, rarity, player) || 0) if rarity && player return (supply.dig(league, rarity) || {}) if rarity supply[league] || {} end |