class ProgressBar::Components::Time
Constants
- ELAPSED_LABEL
- ESTIMATED_LABEL
- NO_TIME_ELAPSED_TEXT
- OOB_FRIENDLY_TIME_TEXT
- OOB_LIMIT_IN_HOURS
- OOB_TIME_FORMATS
- OOB_UNKNOWN_TIME_TEXT
- TIME_FORMAT
Attributes
out_of_bounds_time_format[R]
progress[RW]
timer[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 16 def initialize(options = {}) self.out_of_bounds_time_format = options[:out_of_bounds_time_format] self.timer = options[:timer] self.progress = options[:progress] end
Public Instance Methods
elapsed_with_label()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 26 def elapsed_with_label "#{ELAPSED_LABEL}: #{elapsed}" end
estimated_with_label()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 22 def estimated_with_label "#{ESTIMATED_LABEL}: #{estimated}" end
Protected Instance Methods
estimated_with_friendly_oob()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 44 def estimated_with_friendly_oob self.out_of_bounds_time_format = :friendly estimated_with_elapsed_fallback end
estimated_with_no_oob()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 32 def estimated_with_no_oob self.out_of_bounds_time_format = nil estimated_with_elapsed_fallback end
estimated_with_unknown_oob()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 38 def estimated_with_unknown_oob self.out_of_bounds_time_format = :unknown estimated_with_elapsed_fallback end
out_of_bounds_time_format=(format)
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 54 def out_of_bounds_time_format=(format) unless OOB_TIME_FORMATS.include? format fail 'Invalid Out Of Bounds time format. Valid formats are ' + OOB_TIME_FORMATS.inspect end @out_of_bounds_time_format = format end
Private Instance Methods
elapsed()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 79 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()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 65 def estimated 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 out_of_bounds_time else TIME_FORMAT % [hours, minutes, seconds] end end
estimated_seconds_remaining()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 91 def estimated_seconds_remaining return if progress.unknown? || progress.none? || timer.stopped? (timer.elapsed_seconds * (progress.total / progress.running_average - 1)).round end
estimated_with_elapsed_fallback()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 87 def estimated_with_elapsed_fallback progress.finished? ? elapsed_with_label : estimated_with_label end
out_of_bounds_time()
click to toggle source
# File lib/ruby-progressbar/components/time.rb, line 97 def out_of_bounds_time case out_of_bounds_time_format when :unknown OOB_UNKNOWN_TIME_TEXT when :friendly OOB_FRIENDLY_TIME_TEXT end end