Module: NBA::Teams

Defined in:
lib/nba/teams.rb

Overview

Provides methods to retrieve NBA teams

Class Method Summary collapse

Class Method Details

.allCollection

Retrieves all NBA teams

Examples:

teams = NBA::Teams.all
teams.each { |team| puts team.name }

Returns:



16
17
18
# File 'lib/nba/teams.rb', line 16

def self.all
  Collection.new(Data::TEAMS.map { |data| Team.new(**data) })
end

.find(team_id) ⇒ Team?

Finds a team by ID

Examples:

warriors = NBA::Teams.find(NBA::Team::GSW)

Parameters:

  • team_id (Integer)

    the team ID to find

Returns:

  • (Team, nil)

    the team with the given ID, or nil if not found



27
28
29
30
31
# File 'lib/nba/teams.rb', line 27

def self.find(team_id)
  id = Utils.extract_id(team_id)
  data = Data::TEAMS.find { |t| t.fetch(:id).eql?(id) }
  Team.new(**data) if data
end