Sha256: a35b3dbe39428eab12e125e0cc0dbe5cf936e63d0a7741395f7567d8742b2106

Contents?: true

Size: 576 Bytes

Versions: 6

Compression:

Stored size: 576 Bytes

Contents

# frozen_string_literal: true

require_relative 'autoload'

module CodebreakerKirill
  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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
codebreaker_kirill-1.3.5 lib/codebreaker_kirill/stats.rb
codebreaker_kirill-1.3.4 lib/codebreaker_kirill/stats.rb
codebreaker_kirill-1.3.3 lib/codebreaker_kirill/stats.rb
codebreaker_kirill-1.3.2 lib/codebreaker_kirill/stats.rb
codebreaker_kirill-1.3.1 lib/codebreaker_kirill/stats.rb
codebreaker_kirill-1.3.0 lib/codebreaker_kirill/stats.rb