Module: NBA::CLI::Display

Includes:
PlayerDisplay
Included in:
NBA::CLI
Defined in:
lib/nba/cli/display.rb,
lib/nba/cli/display/player_display.rb

Overview

Helper methods for displaying CLI output

Defined Under Namespace

Modules: PlayerDisplay

Instance Method Summary collapse

Methods included from PlayerDisplay

#display_player, #display_player_draft, #display_player_physical, #display_players

Instance Method Details

#display_games(games_list) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays a list of games in aligned columns

Parameters:

  • games_list (Collection)

    the games to display



14
15
16
17
# File 'lib/nba/cli/display.rb', line 14

def display_games(games_list)
  widths = calculate_game_widths(games_list)
  games_list.each { |game| say(format_game_row(game, widths)) }
end

#display_leaders(leaders_list, category) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays league leaders in aligned format

Parameters:

  • leaders_list (Collection)

    the leaders to display

  • category (String)

    the stat category



149
150
151
152
153
# File 'lib/nba/cli/display.rb', line 149

def display_leaders(leaders_list, category)
  say("League Leaders - #{category.upcase}")
  widths = calculate_leader_widths(leaders_list)
  leaders_list.each { |leader| say(format_leader_row(leader, widths)) }
end

#display_players_list(players) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays a list of players as team roster

Parameters:



126
127
128
129
# File 'lib/nba/cli/display.rb', line 126

def display_players_list(players)
  say("Players:")
  players.each { |player| say(format_detailed_roster_player(player)) }
end

#display_roster(roster_list, team) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays roster for a team

Parameters:

  • roster_list (Collection)

    the roster to display

  • team (Team)

    the team



172
173
174
175
# File 'lib/nba/cli/display.rb', line 172

def display_roster(roster_list, team)
  say("Roster for #{team.full_name}")
  roster_list.each { |player| say(format_detailed_roster_player(player)) }
end

#display_schedule(schedule_list, team) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays schedule for a team

Parameters:

  • schedule_list (Collection)

    the schedule to display

  • team (Team)

    the team



161
162
163
164
# File 'lib/nba/cli/display.rb', line 161

def display_schedule(schedule_list, team)
  say("Schedule for #{team.full_name}")
  schedule_list.each { |game| say(format_schedule_game(game, team)) }
end

#display_standings(standings_list) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays standings in aligned format

Parameters:

  • standings_list (Collection)

    the standings to display



136
137
138
139
140
141
# File 'lib/nba/cli/display.rb', line 136

def display_standings(standings_list)
  widths = calculate_standings_widths(standings_list)
  standings_list.each_with_index do |standing, index|
    say(format_standing_row(standing, index + 1, widths))
  end
end

#display_team(team) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays a single team

Parameters:

  • team (Team)

    the team to display



51
52
53
54
55
56
57
58
59
# File 'lib/nba/cli/display.rb', line 51

def display_team(team)
  detail = TeamDetails.find(team: team)
  say(format_label("Name", team.full_name))
  say(format_label("Founded", team.year_founded))
  display_team_conference(detail)
  display_team_division(detail)
  say(format_label("Coach", detail&.head_coach))
  display_team_championships(team)
end

#display_team_championships(team) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays team championships

Parameters:

  • team (Team)

    the team



90
91
92
93
94
95
96
# File 'lib/nba/cli/display.rb', line 90

def display_team_championships(team)
  stats = fetch_team_year_stats(team)
  championships = stats.select { |s| championship_year?(s) }.map(&:year)
  return if championships.empty?

  say(format_multiline_label("Championships", championships))
end

#display_team_conference(detail) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays team conference info

Parameters:



66
67
68
69
70
71
# File 'lib/nba/cli/display.rb', line 66

def display_team_conference(detail)
  return say(format_label("Conference", nil)) unless detail

  conf = conference_name(detail)
  say(format_label("Conference", conf))
end

#display_team_division(detail) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays team division info

Parameters:



78
79
80
81
82
83
# File 'lib/nba/cli/display.rb', line 78

def display_team_division(detail)
  return say(format_label("Division", nil)) unless detail

  div = division_name(detail)
  say(format_label("Division", div))
end

#display_team_names(teams_list) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays team names only in alphabetical order

Parameters:

  • teams_list (Collection)

    the teams to display



41
42
43
44
# File 'lib/nba/cli/display.rb', line 41

def display_team_names(teams_list)
  sorted = teams_list.sort_by { |team| team.full_name.to_s }
  sorted.each { |team| say(team.full_name) }
end

#display_team_roster(team) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays the roster for a team

Parameters:

  • team (Team)

    the team



114
115
116
117
118
119
# File 'lib/nba/cli/display.rb', line 114

def display_team_roster(team)
  roster_list = Roster.find(team: team)
  return if roster_list.empty?

  display_players_list(roster_list)
end

#display_teams(teams_list, include_roster, detailed:) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays a list of teams

Parameters:

  • teams_list (Collection)

    the teams to display

  • include_roster (Boolean)

    whether to include roster

  • detailed (Boolean)

    whether to show detailed info



26
27
28
29
30
31
32
33
34
# File 'lib/nba/cli/display.rb', line 26

def display_teams(teams_list, include_roster, detailed:)
  return display_team_names(teams_list) unless detailed

  teams_list.each_with_index do |team, index|
    say unless index.zero?
    display_team(team)
    display_team_roster(team) if include_roster
  end
end

#fetch_team_year_stats(team) ⇒ Collection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Fetches team year-by-year stats safely

Parameters:

  • team (Team)

    the team

Returns:



103
104
105
106
107
# File 'lib/nba/cli/display.rb', line 103

def fetch_team_year_stats(team)
  TeamYearByYearStats.find(team: team)
rescue JSON::ParserError
  Collection.new
end