Class: Conscriptor::ProgressReporter
- Inherits:
-
Object
- Object
- Conscriptor::ProgressReporter
- Defined in:
- lib/conscriptor/progress_reporter.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
- #done? ⇒ Boolean
- #inc(name: @name, by: 1) ⇒ Object
-
#initialize(total:, name: nil, report_every: 1, logger: nil) ⇒ ProgressReporter
constructor
A new instance of ProgressReporter.
Constructor Details
#initialize(total:, name: nil, report_every: 1, logger: nil) ⇒ ProgressReporter
Returns a new instance of ProgressReporter.
7 8 9 10 11 12 13 14 |
# File 'lib/conscriptor/progress_reporter.rb', line 7 def initialize(total:, name: nil, report_every: 1, logger: nil) @name = name @total = total @report_every = report_every || 1 @logger = logger || simple_logger @count = 0 @start_time = Time.now end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/conscriptor/progress_reporter.rb', line 5 def count @count end |
Instance Method Details
#done? ⇒ Boolean
30 31 32 |
# File 'lib/conscriptor/progress_reporter.rb', line 30 def done? @count >= @total end |
#inc(name: @name, by: 1) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/conscriptor/progress_reporter.rb', line 16 def inc(name: @name, by: 1) @count += by if @count % @report_every == 0 # rubocop:disable Style/GuardClause percent_complete = 100 * @count / @total time_spent = Time.now - @start_time time_left = @total * time_spent / @count - time_spent @logger.info "#{name} #{@count}/#{@total} (#{percent_complete}%)" \ " #{(time_spent / 60).round(1)}m spent," \ " #{(time_left / 60).round(1)}m to go-ish" end end |