module AlexCodebreaker class PlayersRating attr_accessor :stats def initialize @stats = [] stats_loader end private def stats_loader return unless File.exist?(AlexCodebreaker::Modules::Files::STATS_FILE) load_stats sort_players_rating end def load_stats File.open(AlexCodebreaker::Modules::Files::STATS_FILE) do |file| @stats = Array.new(Psych.load_stream(file)) end end def sort_players_rating @stats.sort_by! { |value| [-value.difficulty_level, value.attempts_used, value.hints_used] } end end end