Sha256: 59222d6ce1cd213ac7e31078d49b19f6a1944db5f1b24a9363811f9fd7106cc2

Contents?: true

Size: 599 Bytes

Versions: 3

Compression:

Stored size: 599 Bytes

Contents

module AlexCodebreaker
  class PlayersRating
    attr_accessor :stats

    def initialize
      @stats = []
      load_and_sort_stats
    end

    private

    def load_and_sort_stats
      return unless File.exist?(AlexCodebreaker.configuration.storage_path)

      load_stats
      sort_stats
    end

    def load_stats
      File.open(AlexCodebreaker.configuration.storage_path) do |file|
        @stats = Array.new(YAML.load_stream(file))
      end
    end

    def sort_stats
      @stats.sort_by! { |value| [-value.difficulty_level, value.attempts_used, value.hints_used] }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alex_codebreaker-0.1.12 lib/alex_codebreaker/players_rating.rb
alex_codebreaker-0.1.11 lib/alex_codebreaker/players_rating.rb
alex_codebreaker-0.1.10 lib/alex_codebreaker/players_rating.rb