Sha256: 5ce636c8e876245b7880147078878a08dfecc9fffb482525e7002a5c21143077

Contents?: true

Size: 641 Bytes

Versions: 4

Compression:

Stored size: 641 Bytes

Contents

require_relative '../constants'
require_relative 'game'
require 'yaml'
module CodebreakerKarolina
  class DBYaml
    include CodebreakerConstants

    def save(game)
      File.open(FILE_NAME, 'a') do |filename|
        YAML.dump(game, filename)
      end
    end

    def statistic
      games = load_file_stats
      return if games.empty?

      games.sort_by do |game|
        [-DIFFICULTY_SORT[game.difficulty.name.to_sym], game.user.used_attempts, game.user.used_hints]
      end
    end

    private

    def load_file_stats
      return [] unless File.file?(FILE_NAME)

      YAML.load_stream(File.open(FILE_NAME))
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
codebreaker_karolina-0.1.9 lib/modules/db_yaml.rb
codebreaker_karolina-0.1.8 lib/modules/db_yaml.rb
codebreaker_karolina-0.1.7 lib/modules/db_yaml.rb
codebreaker_karolina-0.1.6 lib/modules/db_yaml.rb