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