Sha256: 3e085d839ae4d523d653fcc252211d2fa62a4227547f72a8ef6862e50b074632

Contents?: true

Size: 484 Bytes

Versions: 2

Compression:

Stored size: 484 Bytes

Contents

class PlayersRating
  attr_accessor :stats

  def initialize
    stats_loader
  end

  private

  def stats_loader
    return @stats = false unless File.exist?(Files::STATS_FILE)

    load_stats
    sort_players_rating
  end

  def load_stats
    File.open(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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alex_codebreaker-0.1.6 lib/alex_codebreaker/players_rating.rb
alex_codebreaker-0.1.5 lib/alex_codebreaker/players_rating.rb