Class: ProgressBar::Components::Time
- Inherits:
-
Object
- Object
- ProgressBar::Components::Time
- Defined in:
- lib/ruby-progressbar/components/time.rb
Constant Summary collapse
- TIME_FORMAT =
'%02d:%02d:%02d'.freeze
- OOB_TIME_FORMATS =
[:unknown, :friendly, nil].freeze
- OOB_LIMIT_IN_HOURS =
99- OOB_UNKNOWN_TIME_TEXT =
'??:??:??'.freeze
- OOB_FRIENDLY_TIME_TEXT =
'> 4 Days'.freeze
- NO_TIME_ELAPSED_TEXT =
'--:--:--'.freeze
- ESTIMATED_LABEL =
' ETA'.freeze
- ELAPSED_LABEL =
'Time'.freeze
- WALL_CLOCK_FORMAT =
'%H:%M:%S'.freeze
- OOB_TEXT_TO_FORMAT =
{ :unknown => OOB_UNKNOWN_TIME_TEXT, :friendly => OOB_FRIENDLY_TIME_TEXT }.freeze
Instance Method Summary collapse
- #elapsed_with_label ⇒ Object
- #estimated_wall_clock ⇒ Object
- #estimated_with_friendly_oob ⇒ Object
- #estimated_with_label(out_of_bounds_time_format = nil) ⇒ Object
- #estimated_with_no_oob ⇒ Object
- #estimated_with_unknown_oob ⇒ Object
-
#initialize(options = {}) ⇒ Time
constructor
A new instance of Time.
Constructor Details
#initialize(options = {}) ⇒ Time
Returns a new instance of Time.
21 22 23 24 |
# File 'lib/ruby-progressbar/components/time.rb', line 21 def initialize( = {}) self.timer = [:timer] self.progress = [:progress] end |
Instance Method Details
#elapsed_with_label ⇒ Object
30 31 32 |
# File 'lib/ruby-progressbar/components/time.rb', line 30 def elapsed_with_label "#{ELAPSED_LABEL}: #{elapsed}" end |
#estimated_wall_clock ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ruby-progressbar/components/time.rb', line 46 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 ⇒ Object
42 43 44 |
# File 'lib/ruby-progressbar/components/time.rb', line 42 def estimated_with_friendly_oob estimated_with_elapsed_fallback(:friendly) end |
#estimated_with_label(out_of_bounds_time_format = nil) ⇒ Object
26 27 28 |
# File 'lib/ruby-progressbar/components/time.rb', line 26 def estimated_with_label(out_of_bounds_time_format = nil) "#{ESTIMATED_LABEL}: #{estimated(out_of_bounds_time_format)}" end |
#estimated_with_no_oob ⇒ Object
34 35 36 |
# File 'lib/ruby-progressbar/components/time.rb', line 34 def estimated_with_no_oob estimated_with_elapsed_fallback(nil) end |
#estimated_with_unknown_oob ⇒ Object
38 39 40 |
# File 'lib/ruby-progressbar/components/time.rb', line 38 def estimated_with_unknown_oob estimated_with_elapsed_fallback(:unknown) end |