Module: NBA::CLI::Formatters::StandingsFormatters

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

Overview

Formatters for standings-related output

Instance Method Summary collapse

Instance Method Details

#calculate_standings_widths(standings) ⇒ 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 standings display

Returns:

  • (Hash)


20
21
22
# File 'lib/nba/cli/formatters/standings_formatters.rb', line 20

def calculate_standings_widths(standings)
  {rank: standings.size.to_s.length, team: max_length(standings.map(&:team_name))}
end

#format_standing_row(standing, rank, 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 standing row for tabular display

Returns:

  • (String)


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

def format_standing_row(standing, rank, widths)
  rank_str = rank.to_s.rjust(widths.fetch(:rank))
  team = standing.team_name.ljust(widths.fetch(:team))
  "#{rank_str}. #{team} #{standing.wins}-#{standing.losses}"
end