Module: NBA::Static

Defined in:
lib/nba/static.rb

Overview

Provides static data lookup for teams without API calls

Class Method Summary collapse

Class Method Details

.find_team_by_abbreviation(abbreviation) ⇒ Hash?

Finds a team by abbreviation

Examples:

team = NBA::Static.find_team_by_abbreviation("GSW")
team[:full_name] #=> "Golden State Warriors"

Parameters:

  • abbreviation (String)

    the team abbreviation

Returns:

  • (Hash, nil)

    the team hash or nil if not found



40
41
42
# File 'lib/nba/static.rb', line 40

def self.find_team_by_abbreviation(abbreviation)
  Data::TEAMS.find { |t| t.fetch(:abbreviation).casecmp?(abbreviation) }
end

.find_team_by_id(id) ⇒ Hash?

Finds a team by ID

Examples:

team = NBA::Static.find_team_by_id(1610612744)
team[:full_name] #=> "Golden State Warriors"

Parameters:

  • id (Integer)

    the team ID

Returns:

  • (Hash, nil)

    the team hash or nil if not found



28
29
30
# File 'lib/nba/static.rb', line 28

def self.find_team_by_id(id)
  Data::TEAMS.find { |t| t.fetch(:id).eql?(id) }
end

.find_team_by_nickname(nickname) ⇒ Hash?

Finds teams by nickname

Examples:

team = NBA::Static.find_team_by_nickname("Warriors")
team[:city] #=> "San Francisco"

Parameters:

  • nickname (String)

    the team nickname (case-insensitive)

Returns:

  • (Hash, nil)

    the team hash or nil if not found



78
79
80
# File 'lib/nba/static.rb', line 78

def self.find_team_by_nickname(nickname)
  Data::TEAMS.find { |t| t.fetch(:nickname).casecmp?(nickname) }
end

.find_teams_by_city(city) ⇒ Array<Hash>

Finds teams by city name

Examples:

teams = NBA::Static.find_teams_by_city("Los Angeles")
teams.size #=> 2

Parameters:

  • city (String)

    the city name (case-insensitive, partial match)

Returns:

  • (Array<Hash>)

    array of matching team hashes



52
53
54
55
# File 'lib/nba/static.rb', line 52

def self.find_teams_by_city(city)
  pattern = Regexp.new(Regexp.escape(city), Regexp::IGNORECASE)
  Data::TEAMS.select { |t| pattern.match?(t.fetch(:city)) }
end

.find_teams_by_full_name(name) ⇒ Array<Hash>

Finds teams by full name

Examples:

teams = NBA::Static.find_teams_by_full_name("Warriors")
teams.first[:city] #=> "San Francisco"

Parameters:

  • name (String)

    the name to search (case-insensitive, partial match)

Returns:

  • (Array<Hash>)

    array of matching team hashes



90
91
92
93
# File 'lib/nba/static.rb', line 90

def self.find_teams_by_full_name(name)
  pattern = Regexp.new(Regexp.escape(name), Regexp::IGNORECASE)
  Data::TEAMS.select { |t| pattern.match?(t.fetch(:full_name)) }
end

.find_teams_by_state(state) ⇒ Array<Hash>

Finds teams by state name

Examples:

teams = NBA::Static.find_teams_by_state("California")
teams.size #=> 4

Parameters:

  • state (String)

    the state name (case-insensitive, partial match)

Returns:

  • (Array<Hash>)

    array of matching team hashes



65
66
67
68
# File 'lib/nba/static.rb', line 65

def self.find_teams_by_state(state)
  pattern = Regexp.new(Regexp.escape(state), Regexp::IGNORECASE)
  Data::TEAMS.select { |t| pattern.match?(t.fetch(:state)) }
end

.find_teams_by_year_founded(year) ⇒ Array<Hash>

Finds teams by year founded

Examples:

teams = NBA::Static.find_teams_by_year_founded(1946)
teams.size #=> 4

Parameters:

  • year (Integer)

    the founding year

Returns:

  • (Array<Hash>)

    array of matching team hashes



103
104
105
# File 'lib/nba/static.rb', line 103

def self.find_teams_by_year_founded(year)
  Data::TEAMS.select { |t| t.fetch(:year_founded).eql?(year) }
end

.teamsArray<Hash>

Retrieves all NBA teams

Examples:

teams = NBA::Static.teams
teams.size #=> 30

Returns:

  • (Array<Hash>)

    array of team hashes



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

def self.teams
  Data::TEAMS
end