module HighscoresView
Public Class Methods
show(games:)
click to toggle source
# 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
Private Instance Methods
show(games:)
click to toggle source
# 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