Module: CodebreakerVk::Database
- Included in:
- GameConsole, GameMenu
- Defined in:
- lib/codebreaker_vk/database.rb
Constant Summary collapse
- SEED =
'database.yaml'
Instance Method Summary collapse
Instance Method Details
#load(path = SEED) ⇒ Object
7 8 9 |
# File 'lib/codebreaker_vk/database.rb', line 7 def load(path = SEED) YAML.load_file(path) end |
#save(summary, path = SEED) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/codebreaker_vk/database.rb', line 11 def save(summary, path = SEED) row = TableData.new(summary) if File.exist?(path) table = load(path) table << row File.write(path, table.to_yaml) else File.write(path, [row].to_yaml) end end |
#save_results ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/codebreaker_vk/database.rb', line 22 def save_results attempts_total = Game::DIFFICULTY_LEVEL[@game.difficulty][:attempts] hints_total = Game::DIFFICULTY_LEVEL[@game.difficulty][:hints] summary = { name: @game.name, difficulty: @game.difficulty, attempts_total: attempts_total, attempts_used: attempts_total - @game.attempts, hints_total: hints_total, hints_used: hints_total - @game.hints } save(summary) end |