Sha256: fb46696399f1fd6d48268db4b21b2c88108ec6c19720fdfba8881af53da6eb4a

Contents?: true

Size: 582 Bytes

Versions: 1

Compression:

Stored size: 582 Bytes

Contents

module Statistic
  class StatisticSheet
    attr_accessor :new_row

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

    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

    def load
      @storage.load
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codebreaker_kosinskiy-0.1.2 lib/codebreaker/statistic/statistic_sheet.rb