Module: CodebreakerAp::Statistic
- Included in:
- Game
- Defined in:
- lib/codebreaker_ap/modules/statistic.rb
Constant Summary collapse
- STATISTIC_FILE =
File.('../storage_files/statistic.yml', __dir__)
Instance Method Summary collapse
Instance Method Details
#load_statistic ⇒ Object
8 9 10 11 12 13 |
# File 'lib/codebreaker_ap/modules/statistic.rb', line 8 def load_statistic data = YAML.load_stream(File.open(STATISTIC_FILE, 'a+')) return unless data data.sort_by { |players| [-players[:difficulty].length, players[:used_attempts], players[:used_hints]] } end |
#save_stats(player_name, difficulty) ⇒ Object
4 5 6 |
# File 'lib/codebreaker_ap/modules/statistic.rb', line 4 def save_stats(player_name, difficulty) save_to_file(create_statistic_data(player_name, difficulty), STATISTIC_FILE) end |
#show_stats ⇒ Object
15 16 17 18 19 |
# File 'lib/codebreaker_ap/modules/statistic.rb', line 15 def show_stats load_statistic.each_with_index do |value, index| puts statistic(value, index + 1) end end |