Module: NBA::CLI::Formatters::LeadersFormatters

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

Overview

Formatters for leaders-related output

Instance Method Summary collapse

Instance Method Details

#calculate_leader_widths(leaders) ⇒ 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 leader display

Returns:

  • (Hash)


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

def calculate_leader_widths(leaders)
  {rank: max_length(leaders.map(&:rank)), name: max_length(leaders.map(&:player_name))}
end

#format_leader_row(leader, 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 leader row for tabular display

Returns:

  • (String)


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

def format_leader_row(leader, widths)
  rank = leader.rank.to_s.rjust(widths.fetch(:rank))
  name = leader.player_name.ljust(widths.fetch(:name))
  "#{rank}. #{name} #{leader.value}"
end