Class: Statistic::StatisticSheet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage:, row: nil) ⇒ StatisticSheet

Returns a new instance of StatisticSheet.



5
6
7
8
9
# File 'lib/codebreaker/statistic/statistic_sheet.rb', line 5

def initialize(storage:, row: nil)
  @new_row = row
  @rows = nil
  @storage = storage
end

Instance Attribute Details

#new_rowObject

Returns the value of attribute new_row.



3
4
5
# File 'lib/codebreaker/statistic/statistic_sheet.rb', line 3

def new_row
  @new_row
end

Instance Method Details

#loadObject



23
24
25
# File 'lib/codebreaker/statistic/statistic_sheet.rb', line 23

def load
  @storage.load
end

#storeObject



11
12
13
14
15
16
17
18
19
20
21
# 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