class ProgressBar::Components::Time
Constants
- ELAPSED_LABEL
- ESTIMATED_LABEL
- NO_TIME_ELAPSED_TEXT
- OOB_FRIENDLY_TIME_TEXT
- OOB_LIMIT_IN_HOURS
- OOB_TEXT_TO_FORMAT
- OOB_TIME_FORMATS
- OOB_UNKNOWN_TIME_TEXT
- TIME_FORMAT
- WALL_CLOCK_FORMAT
Attributes
progress[RW]
projector[RW]
timer[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 21 def initialize(options = {}) self.timer = options[:timer] self.progress = options[:progress] self.projector = options[:projector] end
Public Instance Methods
elapsed_with_label()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 31 def elapsed_with_label "#{ELAPSED_LABEL}: #{elapsed}" end
estimated_wall_clock()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 47 def estimated_wall_clock return timer.stopped_at.strftime(WALL_CLOCK_FORMAT) if progress.finished? return NO_TIME_ELAPSED_TEXT unless timer.started? memo_estimated_seconds_remaining = estimated_seconds_remaining return NO_TIME_ELAPSED_TEXT unless memo_estimated_seconds_remaining (timer.now + memo_estimated_seconds_remaining). strftime(WALL_CLOCK_FORMAT) end
estimated_with_friendly_oob()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 43 def estimated_with_friendly_oob estimated_with_elapsed_fallback(:friendly) end
estimated_with_label(out_of_bounds_time_format = nil)
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 27 def estimated_with_label(out_of_bounds_time_format = nil) "#{ESTIMATED_LABEL}: #{estimated(out_of_bounds_time_format)}" end
estimated_with_no_oob()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 35 def estimated_with_no_oob estimated_with_elapsed_fallback(nil) end
estimated_with_unknown_oob()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 39 def estimated_with_unknown_oob estimated_with_elapsed_fallback(:unknown) end
Private Instance Methods
elapsed()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 80 def elapsed return NO_TIME_ELAPSED_TEXT unless timer.started? hours, minutes, seconds = timer.divide_seconds(timer.elapsed_whole_seconds) TIME_FORMAT % [hours, minutes, seconds] end
estimated(out_of_bounds_time_format)
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 66 def estimated(out_of_bounds_time_format) memo_estimated_seconds_remaining = estimated_seconds_remaining return OOB_UNKNOWN_TIME_TEXT unless memo_estimated_seconds_remaining hours, minutes, seconds = timer.divide_seconds(memo_estimated_seconds_remaining) if hours > OOB_LIMIT_IN_HOURS && out_of_bounds_time_format OOB_TEXT_TO_FORMAT.fetch(out_of_bounds_time_format) else TIME_FORMAT % [hours, minutes, seconds] end end
estimated_seconds_remaining()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 94 def estimated_seconds_remaining return if progress.unknown? || projector.none? || progress.none? || timer.stopped? || timer.reset? (timer.elapsed_seconds * ((progress.total / projector.projection) - 1)).round end
estimated_with_elapsed_fallback(out_of_bounds_time_format)
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 88 def estimated_with_elapsed_fallback(out_of_bounds_time_format) return elapsed_with_label if progress.finished? estimated_with_label(out_of_bounds_time_format) end