Module: NBA::CLI::Formatters::GameFormatters

Included in:
NBA::CLI::Formatters
Defined in:
lib/nba/cli/formatters/game_formatters.rb

Overview

Formatters for game-related output

Instance Method Summary collapse

Instance Method Details

#calculate_game_widths(games) ⇒ Hash

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.

Calculates column widths for game display



50
51
52
53
54
55
# File 'lib/nba/cli/formatters/game_formatters.rb', line 50

def calculate_game_widths(games)
  {status: max_length(games.map { |g| format_game_status(g) }),
   home: max_length(games.map { |g| team_nickname(g.home_team) }),
   away: max_length(games.map { |g| team_nickname(g.away_team) }),
   **score_widths(games)}
end

#determine_opponent(game, team) ⇒ String

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.

Determines the opponent display string



79
80
81
82
# File 'lib/nba/cli/formatters/game_formatters.rb', line 79

def determine_opponent(game, team)
  home_game = game.home_team_tricode.eql?(team.abbreviation)
  home_game ? "vs #{game.away_team_tricode}" : "@ #{game.home_team_tricode}"
end

#format_game_row(game, widths) ⇒ String

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.

Formats a game row for tabular display



21
22
23
24
25
26
# File 'lib/nba/cli/formatters/game_formatters.rb', line 21

def format_game_row(game, widths)
  status = center(format_game_status(game), widths.fetch(:status))
  teams = format_game_teams(game, widths)
  scores = format_game_scores(game, widths)
  "#{status} - #{teams.fetch(:home)} #{scores.fetch(:home)} : #{scores.fetch(:away)} #{teams.fetch(:away)}".rstrip
end

#format_game_scores(game, widths) ⇒ Hash

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.

Formats game scores with padding



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

def format_game_scores(game, widths)
  {home: center(game.home_score || "-", widths.fetch(:home_score)),
   away: center(game.away_score || "-", widths.fetch(:away_score))}
end

#format_game_status(game) ⇒ String

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.

Formats a game status for display



10
11
12
13
14
15
# File 'lib/nba/cli/formatters/game_formatters.rb', line 10

def format_game_status(game)
  status = game.status
  return "TBD" unless status

  convert_et_to_local(status.strip)
end

#format_game_teams(game, widths) ⇒ Hash

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.

Formats game team names with padding



32
33
34
35
# File 'lib/nba/cli/formatters/game_formatters.rb', line 32

def format_game_teams(game, widths)
  {home: center(team_nickname(game.home_team), widths.fetch(:home)),
   away: center(team_nickname(game.away_team), widths.fetch(:away))}
end

#format_schedule_game(game, team) ⇒ String

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.

Formats a scheduled game for display



70
71
72
73
# File 'lib/nba/cli/formatters/game_formatters.rb', line 70

def format_schedule_game(game, team)
  date = game.game_date&.split("T")&.first || "TBD"
  "#{date}: #{determine_opponent(game, team)}"
end

#score_widths(games) ⇒ Hash

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.

Calculates score column widths



61
62
63
64
# File 'lib/nba/cli/formatters/game_formatters.rb', line 61

def score_widths(games)
  {home_score: max_length(games.map(&:home_score)),
   away_score: max_length(games.map(&:away_score))}
end