Method: Progressor::LimitedSequence#to_s

Defined in:
lib/progressor/limited_sequence.rb

#to_sObject

Outputs a textual representation of the current state of the LimitedSequence. Shows:

  • the current number of iterations and the total count

  • completion level in percentage

  • how long a single iteration takes

  • estimated time of arrival (ETA) – time until it’s done

A custom formatter provided at construction time overrides this default output.

If the “current” number of iterations goes over the total count, an ETA can’t be shown anymore, so it’ll just be the current number over the expected one, and the time per iteration.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/progressor/limited_sequence.rb', line 78

def to_s
  return @formatter.call(self).to_s if @formatter

  if @current > @total_count
    return [
      "#{@current} (expected #{@total_count})",
      "t/i: #{format_time(per_iteration)}",
      "ETA: ???",
    ].join(', ')
  end

  [
    "#{@current.to_s.rjust(@total_count_digits, '0')}/#{@total_count}",
    "#{((@current / @total_count.to_f) * 100).round.to_s.rjust(3, '0')}%",
    "t/i: #{format_time(per_iteration)}",
    "ETA: #{format_time(eta)}",
  ].join(', ')
end