Class: Sorare::Rewards::Player

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.playing_players[slug]
  load_supply(reward_data)
end

Instance Attribute Details

#slugObject (readonly)

Returns the value of attribute slug.



10
11
12
# File 'lib/sorare/rewards/player.rb', line 10

def slug
  @slug
end

#supplyObject (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

Returns:

  • (Boolean)


40
41
42
# File 'lib/sorare/rewards/player.rb', line 40

def playing?
  @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

#supply_for(league, rarity) ⇒ Object



48
49
50
# File 'lib/sorare/rewards/player.rb', line 48

def supply_for(league, rarity)
  supply.dig(league.name, rarity, 'supply') || Supply.new
end