Class: DataBaseManager

Inherits:
Object
  • Object
show all
Defined in:
lib/src/data_base_manager.rb

Instance Method Summary collapse

Instance Method Details

#load_game_resultsObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/src/data_base_manager.rb', line 9

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

#save_game_results(attributes) ⇒ Object



2
3
4
5
6
7
# File 'lib/src/data_base_manager.rb', line 2

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