Class: CodebreakerKarolina::DBYaml

Inherits:
Object
  • Object
show all
Includes:
CodebreakerConstants
Defined in:
lib/modules/db_yaml.rb

Constant Summary

Constants included from CodebreakerConstants

CodebreakerConstants::CODE_SIZE, CodebreakerConstants::DIFFICULTY, CodebreakerConstants::DIFFICULTY_SORT, CodebreakerConstants::FILE_NAME, CodebreakerConstants::MINUS, CodebreakerConstants::NUM_RANGE, CodebreakerConstants::PLUS

Instance Method Summary collapse

Instance Method Details

#save(game) ⇒ Object



8
9
10
11
12
# File 'lib/modules/db_yaml.rb', line 8

def save(game)
  File.open(FILE_NAME, 'a') do |filename|
    YAML.dump(game, filename)
  end
end

#statisticObject



14
15
16
17
18
19
20
21
# File 'lib/modules/db_yaml.rb', line 14

def statistic
  games = load_file_stats
  return if games.empty?

  games.sort_by do |game|
    [-DIFFICULTY_SORT[game.difficulty.name.to_sym], game.user.used_attempts, game.user.used_hints]
  end
end