class AlexCodebreaker::PlayersRating

Attributes

stats[RW]

Public Class Methods

new() click to toggle source
# File lib/alex_codebreaker/players_rating.rb, line 5
def initialize
  @stats = []
  load_and_sort_stats
end

Private Instance Methods

load_and_sort_stats() click to toggle source
# File lib/alex_codebreaker/players_rating.rb, line 12
def load_and_sort_stats
  return unless File.exist?(winners_path)

  load_stats
  sort_stats
end
load_stats() click to toggle source
# File lib/alex_codebreaker/players_rating.rb, line 19
def load_stats
  File.open(winners_path) do |file|
    @stats = Array.new(YAML.load_stream(file))
  end
end
sort_stats() click to toggle source
# File lib/alex_codebreaker/players_rating.rb, line 25
def sort_stats
  @stats.sort_by! { |value| [-value.difficulty_level, value.attempts_used, value.hints_used] }
end
winners_path() click to toggle source
# File lib/alex_codebreaker/players_rating.rb, line 29
def winners_path
  "#{AlexCodebreaker.configuration.winners_folder_path}#{AlexCodebreaker::Session::WINNERS_FILE_NAME}"
end