Module: NBA::CLI::Formatters

Includes:
GameFormatters, LeadersFormatters, PlayerFormatters, StandingsFormatters, TeamFormatters, TimeFormatters
Included in:
NBA::CLI
Defined in:
lib/nba/cli/formatters.rb,
lib/nba/cli/formatters/game_formatters.rb,
lib/nba/cli/formatters/team_formatters.rb,
lib/nba/cli/formatters/time_formatters.rb,
lib/nba/cli/formatters/player_formatters.rb,
lib/nba/cli/formatters/leaders_formatters.rb,
lib/nba/cli/formatters/standings_formatters.rb

Overview

Helper methods for formatting CLI output

Defined Under Namespace

Modules: GameFormatters, LeadersFormatters, PlayerFormatters, StandingsFormatters, TeamFormatters, TimeFormatters

Constant Summary collapse

LABEL_WIDTH =

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

Standard label width for formatted output

Returns:

  • (Integer)
16

Constants included from TeamFormatters

TeamFormatters::DIVISIONS, TeamFormatters::EAST

Constants included from TimeFormatters

TimeFormatters::ET_TIME_PATTERN

Instance Method Summary collapse

Methods included from PlayerFormatters

#format_detailed_roster_player, #format_draft_info, #format_jersey_number, #format_player_result, #format_position

Methods included from LeadersFormatters

#calculate_leader_widths, #format_leader_row

Methods included from StandingsFormatters

#calculate_standings_widths, #format_standing_row

Methods included from GameFormatters

#calculate_game_widths, #determine_opponent, #format_game_row, #format_game_scores, #format_game_status, #format_game_teams, #format_schedule_game, #score_widths

Methods included from TeamFormatters

#championship_year?, #conference_name, #division_for_team, #division_name, #team_nickname

Methods included from TimeFormatters

#build_et_time, #convert_et_to_local, #convert_to_24h, #format_local_time, #local_time_zone_abbr, #parse_et_time

Instance Method Details

#center(value, width) ⇒ 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.

Centers a value within the given width

Returns:

  • (String)


35
# File 'lib/nba/cli/formatters.rb', line 35

def center(value, width) = value.to_s.center(width)

#format_label(label, value) ⇒ 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 label and value as a single line

Returns:

  • (String)


41
# File 'lib/nba/cli/formatters.rb', line 41

def format_label(label, value) = "#{label}: #{value}"

#format_multiline_label(label, items) ⇒ 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 label with multiple items across lines

Returns:

  • (String)


47
48
49
50
51
52
53
# File 'lib/nba/cli/formatters.rb', line 47

def format_multiline_label(label, items)
  indent = " " * (label.length + 2)
  lines = items.each_slice(2).map { |pair| pair.join(", ") }
  first_line = "#{label}: #{lines.first}"
  continuation = lines.drop(1).map { |line| "#{indent}#{line}" }
  ([first_line] + continuation).join("\n")
end

#max_length(values) ⇒ Integer

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.

Returns the maximum string length from the given values

Returns:

  • (Integer)


29
# File 'lib/nba/cli/formatters.rb', line 29

def max_length(values) = values.map { |v| v.to_s.length }.max