Module: NBA::Players

Defined in:
lib/nba/players.rb

Overview

Provides methods to retrieve NBA players

Class Method Summary collapse

Class Method Details

.all(season: Utils.current_season, only_current: true, client: CLIENT) ⇒ Collection

Retrieves all NBA players

Examples:

players = NBA::Players.all
players.each { |player| puts player.full_name }


19
20
21
22
23
# File 'lib/nba/players.rb', line 19

def self.all(season: Utils.current_season, only_current: true, client: CLIENT)
  current_flag = only_current ? 1 : 0
  path = "commonallplayers?LeagueID=00&Season=#{Utils.format_season(season)}&IsOnlyCurrentSeason=#{current_flag}"
  ResponseParser.parse(client.get(path)) { |data| build_player_summary(data) }
end

.find(player_id, client: CLIENT) ⇒ Player?

Finds a player by ID

Examples:

roster = NBA::Roster.find(team: NBA::Team::GSW)
curry = roster.find { |p| p.jersey_number == 30 }
player = NBA::Players.find(curry.id)


35
36
37
38
39
40
41
# File 'lib/nba/players.rb', line 35

def self.find(player_id, client: CLIENT)
  id = Utils.extract_id(player_id)
  return unless id

  path = "commonplayerinfo?PlayerID=#{id}"
  ResponseParser.parse_single(client.get(path)) { |data| build_player_detail(data) }
end