Class: Statistic::StatisticSheet
- Inherits:
-
Object
- Object
- Statistic::StatisticSheet
- Defined in:
- lib/codebreaker/statistic/statistic_sheet.rb
Instance Attribute Summary collapse
-
#new_row ⇒ Object
Returns the value of attribute new_row.
Instance Method Summary collapse
-
#initialize(storage:, row: nil) ⇒ StatisticSheet
constructor
A new instance of StatisticSheet.
- #load ⇒ Object
- #store ⇒ Object
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_row ⇒ Object
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
#load ⇒ Object
23 24 25 |
# File 'lib/codebreaker/statistic/statistic_sheet.rb', line 23 def load @storage.load end |
#store ⇒ Object
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, | row. = + 1 } end @storage.store(@rows) end |