Sha256: bfb2160b61c8cca2c6771bcc1bf76779898b3d43cf92e00a2e50b01b255260fd

Contents?: true

Size: 638 Bytes

Versions: 1

Compression:

Stored size: 638 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

1 entries across 1 versions & 1 rubygems

Version Path
codebreaker_karolina-0.1.5 lib/modules/db_yaml.rb