# frozen_string_literal: true module Codebreaker DB_PATH = './database/database.yml' class Database class << self def load_stats load_db.sort_by! { |game| [game[:difficulty], game[:attempts_used], game[:hints_used]] } end def save(results) database = load_db << results File.open(DB_PATH, 'w+') { |file| file.write(database.to_yaml) } end private def load_db return YAML.load_file(DB_PATH) if File.exist?(DB_PATH) [] end end end end