Sha256: 0e4e3458deaa4b97bae53a57ff596a9fa63ed344789c2de73120123574184e92

Contents?: true

Size: 606 Bytes

Versions: 1

Compression:

Stored size: 606 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alex_codebreaker-0.1.7 lib/alex_codebreaker/players_rating.rb