Sha256: b9a3a0fd77d5f1bc583f18c7a696c04ab18550baaab58dd16373cf957f6c8de6

Contents?: true

Size: 581 Bytes

Versions: 1

Compression:

Stored size: 581 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_hits_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.0 lib/codebreaker/statistic/statistic_sheet.rb