Class: TTY::ProgressBar::EstimatedFormatter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/progressbar/formatter/estimated.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Used by Pipeline to format :eta token

Instance Method Summary collapse

Instance Method Details

#call(value) ⇒ Object

Format :eta token

Parameters:

  • value (String)

    the value to format



20
21
22
23
24
25
26
27
28
29
30
31
# 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