Sha256: 3bad0a369fd439a8e3f45508485327f41f4d8067db8ae4cf0d4af6c41748f78b

Contents?: true

Size: 718 Bytes

Versions: 1

Compression:

Stored size: 718 Bytes

Contents

class DataBaseManager
  def save_game_results(attributes)
    data = { name: attributes[0], difficulty: attributes[1], attempts_total: attributes[2],
             attempts_used: attributes[3], hints_total: attributes[4], hints_used: attributes[5] }
    Dir.mkdir('lib/db') unless Dir.exist?('lib/db')
    File.open('lib/db/codebreaker_db.yml', 'a') { |file| file.puts(data.to_yaml) }
  end

  def load_game_results
    game_results = []
    return game_results unless Dir.exist?('lib/db') || File.exist?('lib/db/codebreaker_db.yml')

    File.open('lib/db/codebreaker_db.yml') do |yaml_file|
      YAML.load_stream(yaml_file) do |document|
        game_results << document
      end
    end
    game_results
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codebreaker_vv-2.0.0 lib/src/data_base_manager.rb