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 25 |
# File 'lib/ruby-progressbar/components/time.rb', line 21 def initialize( = {}) self.timer = [:timer] self.progress = [:progress] self.projector = [:projector] end |
Instance Method Details
#elapsed_with_label ⇒ Object
31 32 33 |
# File 'lib/ruby-progressbar/components/time.rb', line 31 def elapsed_with_label "#{ELAPSED_LABEL}: #{elapsed}" end |
#estimated_wall_clock ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
43 44 45 |
# 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) ⇒ Object
27 28 29 |
# 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 ⇒ Object
35 36 37 |
# File 'lib/ruby-progressbar/components/time.rb', line 35 def estimated_with_no_oob estimated_with_elapsed_fallback(nil) end |
#estimated_with_unknown_oob ⇒ Object
39 40 41 |
# File 'lib/ruby-progressbar/components/time.rb', line 39 def estimated_with_unknown_oob estimated_with_elapsed_fallback(:unknown) end |