Module: IcodebreakerGem::Storage
- Included in:
- Game
- Defined in:
- lib/modules/storage.rb
Constant Summary collapse
- DATA_FILE =
'codebreakers.yml'
- STORAGE_PATH =
'./storage/'
Class Method Summary collapse
Class Method Details
.load_storage ⇒ Object
18 19 20 21 |
# File 'lib/modules/storage.rb', line 18 def load_storage create_storage YAML.load(File.read(data_path)) || [] end |
.save_storage(game) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/modules/storage.rb', line 9 def save_storage(game) create_storage games = load_storage games << game File.open(data_path, 'w') do |file| YAML.dump(games, file) end end |
.sort_codebreakers ⇒ Object
23 24 25 26 27 |
# File 'lib/modules/storage.rb', line 23 def sort_codebreakers load_storage.sort_by do |statistic| [statistic[:attempts_total], statistic[:attempts_used], statistic[:hints_used]] end end |