Sha256: 3449e64e0634112368741e127aca1a33d68947feacdf017a698e36e2a3195656
Contents?: true
Size: 888 Bytes
Versions: 1
Compression:
Stored size: 888 Bytes
Contents
module Fortschritt class Meter attr_accessor :total, :done, :updated_at, :average_seconds def initialize(total) @total = total @done = 0 @updated_at = Time.now @average_seconds = 0 end def increment @_now = Time.now elapsed_seconds = @_now - updated_at @average_seconds = calculate_average_seconds(elapsed_seconds) @updated_at = @_now @done += 1 print! end def completed? done >= total end def remaining_seconds remaining * average_seconds end def remaining [total - done, 0].max end def calculate_average_seconds(value) average_seconds.zero? and return value ((average_seconds * done) + value) / (done + 1) end def print! Fortschritt.printer.print(self) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fortschritt-0.1.1 | lib/fortschritt/meter.rb |