Class: Sorare::Rewards::Player
- Inherits:
-
Object
- Object
- Sorare::Rewards::Player
- Defined in:
- lib/sorare/rewards/player.rb
Overview
Player stores the reward data of a player for a game week
Defined Under Namespace
Classes: Supply
Instance Attribute Summary collapse
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#supply ⇒ Object
readonly
Returns the value of attribute supply.
Instance Method Summary collapse
-
#initialize(slug, reward_data) ⇒ Player
constructor
A new instance of Player.
- #playing? ⇒ Boolean
- #rank(league, rarity) ⇒ Object
- #rewarded_under_cooldown(league, rarity) ⇒ Object
- #supply_for(league, rarity) ⇒ Object
Constructor Details
#initialize(slug, reward_data) ⇒ Player
Returns a new instance of Player.
26 27 28 29 30 31 32 |
# File 'lib/sorare/rewards/player.rb', line 26 def initialize(slug, reward_data) @slug = slug @supply = Hash.new { |h, k| h[k] = {} } @config = reward_data.config @game_data = reward_data.[slug] load_supply(reward_data) end |
Instance Attribute Details
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
10 11 12 |
# File 'lib/sorare/rewards/player.rb', line 10 def slug @slug end |
#supply ⇒ Object (readonly)
Returns the value of attribute supply.
10 11 12 |
# File 'lib/sorare/rewards/player.rb', line 10 def supply @supply end |
Instance Method Details
#playing? ⇒ Boolean
40 41 42 |
# File 'lib/sorare/rewards/player.rb', line 40 def @game_data.present? end |
#rank(league, rarity) ⇒ Object
44 45 46 |
# File 'lib/sorare/rewards/player.rb', line 44 def rank(league, rarity) @supply.dig(league.name, rarity, 'rank') end |
#rewarded_under_cooldown(league, rarity) ⇒ Object
52 53 54 55 56 |
# File 'lib/sorare/rewards/player.rb', line 52 def rewarded_under_cooldown(league, rarity) rewarded(league, rarity).count do |at| (Time.parse(at) + @config.cooldown_since(rarity)) > Time.now end end |