Module: HighscoresView

Defined in:
lib/views/highscores_view.rb

Class Method Summary collapse

Class Method Details

.show(games:) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/views/highscores_view.rb', line 4

def show(games:) 
    puts "Leaderboard:".colorize(:light_yellow)
    return puts "\nNo scores on the leaderboard to show!".colorize(:red) if games.empty?
    headers = ['Player'.colorize(:light_blue), 'Score'.colorize(:light_magenta)]
    # top_10 stores the highest 10 scores in YAML, sorted in descending order
    top_10 = games.sort_by{|ary|ary[1]}.reverse[0..9]
    highscores = TTY::Table.new(header: headers, rows: top_10)
    puts highscores.render :unicode, alignments: [:left, :right]
end