# frozen_string_literal: true module Codebreaker PATH = './db' FILE_NAME = 'data.yml' module Storage class << self def save(results) FileUtils.mkdir_p(PATH) unless Dir.exist?(PATH) data = load << results File.open(File.join(Dir.pwd, PATH, FILE_NAME), 'a+') { |file| file.write(data.to_yaml) } end def load YAML.safe_load(File.join(Dir.pwd, PATH, FILE_NAME)) [] end def sort_player load_database.sort_by { |game| [game[:difficulty], game[:attempts_used], game[:hints_used]] } end end end end