Sha256: 28b93edee4127e872ebc1493b6760e7009b7d60e0b0f1b9f8276a2874f48d033

Contents?: true

Size: 601 Bytes

Versions: 1

Compression:

Stored size: 601 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::Modules::Files::STATS_FILE)

      load_stats
      sort_stats
    end

    def load_stats
      File.open(AlexCodebreaker::Modules::Files::STATS_FILE) 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

1 entries across 1 versions & 1 rubygems

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