Class: TTY::ProgressBar::EstimatedTimeFormatter Private
- Inherits:
-
Object
- Object
- TTY::ProgressBar::EstimatedTimeFormatter
- Defined in:
- lib/tty/progressbar/formatter/estimated_time.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_time token
Instance Method Summary collapse
-
#call(value) ⇒ Object
Format :eta_time token.
Instance Method Details
#call(value) ⇒ Object
Format :eta_time token
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tty/progressbar/formatter/estimated_time.rb', line 17 def call(value) if @progress.indeterminate? || (@progress.elapsed_time.zero? && @progress.ratio.zero?) return value.gsub(matcher, "--:--:--") end elapsed = @progress.elapsed_time estimated = @progress.ratio.zero? ? 0.0 : (elapsed / @progress.ratio).to_f estimated -= elapsed estimated = 0.0 if estimated < 0 time_format = if estimated >= 86_400 # longer than a day "%Y-%m-%d %H:%M:%S" else "%H:%M:%S" end completion_time = Time.now + estimated eta_time = completion_time.strftime(time_format) value.gsub(matcher, eta_time) end |