Sha256: b371a1596a9b69f2b40af271bf89ca6656efdfdbad0a83d6f2055bf17ce441f8

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

# frozen_string_literal: true

require 'yaml'
require_relative 'user'

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.each_with_index do |user, index|
      stats_format(user, index)
    end
  end

  def self.stats_format(user, index)
    index += 1
    puts "Rating: #{index}", "Name: #{user.name}",
         "Difficulty: #{Settings::DIFFICULTY.key({ attempts: user.attempts[:all], hints: user.hints[:all] })}",
         "Available Attempts: #{user.attempts[:all]}",
         "Used Attempts: #{user.attempts[:used]}",
         "Available Hints: #{user.hints[:all]}",
         "Used Hints: #{user.hints[:used]}",
         '-----------------------'
  end
end

Stats.show_stats

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codebreaker_kirill-0.3.2 lib/codebreaker_kirill/stats.rb