Module: Codebreaker::Storage
Constant Summary collapse
- PATH =
'db'
- FILE_NAME =
'data.yml'
Instance Method Summary collapse
Instance Method Details
#load_database ⇒ Object
15 16 17 |
# File 'lib/modules/storage.rb', line 15 def load_database YAML.load(File.read(file_path)) end |
#save(results) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/modules/storage.rb', line 8 def save(results) FileUtils.mkdir_p(PATH) unless Dir.exist?(PATH) create_storage unless File.exist?(file_path) data = load_database << results write_data(data) end |
#sort_player ⇒ Object
19 20 21 22 |
# File 'lib/modules/storage.rb', line 19 def sort_player create_storage unless File.exist?(file_path) load_database.sort_by { |game| [game[:difficulty], game[:attempts_used], game[:hints_used]] } end |