Sha256: 3a8338c119af24ae6ee2653d6e1e6815c539c0e6f10ab186d6762b03c8910c88

Contents?: true

Size: 534 Bytes

Versions: 8

Compression:

Stored size: 534 Bytes

Contents

# 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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
codebreaker-d3n-0.2.1 lib/codebreaker/database.rb
codebreaker-d3n-0.2.0 lib/codebreaker/database.rb
codebreaker-d3n-0.1.9 lib/codebreaker/database.rb
codebreaker-d3n-0.1.8 lib/codebreaker/database.rb
codebreaker-d3n-0.1.7 lib/codebreaker/database.rb
codebreaker-d3n-0.1.2 lib/codebreaker/database.rb
codebreaker-d3n-0.1.1 lib/codebreaker/database.rb
codebreaker-d3n-0.1.0 lib/codebreaker/database.rb