Sha256: 7ccb41ecab529d069a1d7b4becd26726075f7a9173cc774694a47fe52a1761c3

Contents?: true

Size: 523 Bytes

Versions: 3

Compression:

Stored size: 523 Bytes

Contents

# frozen_string_literal: true

require_relative 'autoload'

class Stats
  def self.save_game(user)
    @data = File.exist?('stats.yml') ? YAML.load_file('stats.yml') : []
    @data << user
    File.new('stats.yml', 'w') unless File.exist?('stats.yml')
    File.open('stats.yml', 'w') { |file| file.write(@data.to_yaml) }
  end

  def self.show_stats
    @data = File.exist?('stats.yml') ? YAML.load_file('stats.yml') : []
    @data.sort_by! { |user| [user.level[:attempts], user.attempts_used, user.hints_used] }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
codebreaker_kirill-1.2.4 lib/codebreaker_kirill/stats.rb
codebreaker_kirill-1.2.3 lib/codebreaker_kirill/stats.rb
codebreaker_kirill-1.2.1 lib/codebreaker_kirill/stats.rb