Class: Codebreaker::Statistics

Inherits:
Object
  • Object
show all
Defined in:
lib/codebreaker/statistics.rb

Constant Summary collapse

DEFAULT_PATH_TO_FILE =
"./lib/codebreaker/data/stat.yml".freeze

Instance Method Summary collapse

Constructor Details

#initialize(path_to_file = DEFAULT_PATH_TO_FILE) ⇒ Statistics



5
6
7
# File 'lib/codebreaker/statistics.rb', line 5

def initialize(path_to_file = DEFAULT_PATH_TO_FILE)
  @storage = StorageInterceptor.new(path_to_file)
end

Instance Method Details

#statsObject



9
10
11
12
13
14
# File 'lib/codebreaker/statistics.rb', line 9

def stats
  return unless codebreaker_data = @storage.read_database

  codebreaker_data.sort_by! { |stat| [stat[:level_num], stat[:hints], stat[:attempts]] }
  codebreaker_data.each { |stat| stat.delete_if { |key, _value| key == :level_num } }
end