class Statistic::StatisticSheet

Attributes

new_row[RW]

Public Class Methods

new(storage:, row: nil) click to toggle source
# File lib/codebreaker/statistic/statistic_sheet.rb, line 5
def initialize(storage:, row: nil)
  @new_row = row
  @rows = nil
  @storage = storage
end

Public Instance Methods

load() click to toggle source
# File lib/codebreaker/statistic/statistic_sheet.rb, line 23
def load
  @storage.load
end
store() click to toggle source
# File lib/codebreaker/statistic/statistic_sheet.rb, line 11
def store
  @rows = Array(load)
  if @rows.nil?
    @rows = @new_row
  else
    @rows.append(@new_row)
    @rows.sort_by! { |row| [row.init_attempts_count, row.used_attempts_count, row.used_hints_count] }
    @rows.map.with_index { |row, rating| row.rating = rating + 1 }
  end
  @storage.store(@rows)
end