class TTY::ProgressBar::EstimatedFormatter

Used by {Pipeline} to format :eta token

@api private

Public Instance Methods

call(value) click to toggle source

Format :eta token

@param [String] value

the value to format

@api public

# File lib/tty/progressbar/formatter/estimated.rb, line 20
def call(value)
  if @progress.indeterminate? ||
     (@progress.elapsed_time.zero? && @progress.ratio.zero?)
    return value.gsub(matcher, "--s")
  end

  elapsed = @progress.elapsed_time
  estimated = @progress.ratio.zero? ? 0.0 : (elapsed / @progress.ratio).to_f
  estimated -= elapsed
  estimated = 0.0 if estimated < 0
  value.gsub(matcher, Converter.to_time(estimated))
end