Class: TT::Progressbar
- Inherits:
-
Object
- Object
- TT::Progressbar
- Defined in:
- TT_Lib2/progressbar.rb
Overview
Wrapper for displaying progress to the user.
Instance Method Summary collapse
- #elapsed_time(format = false) ⇒ Numeric|String
- #estimated_time_left(format = false) ⇒ Numeric|String
- #increment(amount = 1) ⇒ Numeric (also: #next)
- #index ⇒ Numeric
-
#initialize(range = nil, task_name = 'Processing', decimals_places = 1) ⇒ Progressbar
constructor
A new instance of Progressbar.
- #size ⇒ Numeric
- #value=(new_value) ⇒ Numeric
Constructor Details
#initialize(range = nil, task_name = 'Processing', decimals_places = 1) ⇒ Progressbar
Returns a new instance of Progressbar
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'TT_Lib2/progressbar.rb', line 38 def initialize( range=nil, task_name='Processing', decimals_places=1 ) if range.nil? @start = 0 @end = 0 elsif range.is_a?( Range ) @start = range.first @end = range.last elsif range.is_a?( Numeric ) @start = 0 @end = range else [:length, :count, :size, :count_instances].each { |method| if range.respond_to?( method ) @start = 0 @end = range.send( method ) end } if @start.nil? raise( ArgumentError, 'Must be Range, Numeric or collection.' ) end end @start = @start.to_f @end = @end.to_f @task_name = task_name @decimals = decimals_places.to_i reset() end |
Instance Method Details
#elapsed_time(format = false) ⇒ Numeric|String
118 119 120 121 |
# File 'TT_Lib2/progressbar.rb', line 118 def elapsed_time(format=false) elapsed = Time.now - @start_time (format) ? TT::format_time(elapsed) : elapsed end |
#estimated_time_left(format = false) ⇒ Numeric|String
130 131 132 133 134 135 |
# File 'TT_Lib2/progressbar.rb', line 130 def estimated_time_left(format=false) elapsed = elapsed_time() ratio = size() / index() remaining = (elapsed * ratio) - elapsed (format) ? TT::format_time(remaining) : remaining end |
#increment(amount = 1) ⇒ Numeric Also known as: next
73 74 75 76 77 |
# File 'TT_Lib2/progressbar.rb', line 73 def increment(amount=1) @value += amount.abs updateUI() @value end |
#index ⇒ Numeric
107 108 109 |
# File 'TT_Lib2/progressbar.rb', line 107 def index @value - @start end |
#size ⇒ Numeric
98 99 100 |
# File 'TT_Lib2/progressbar.rb', line 98 def size @end - @start end |
#value=(new_value) ⇒ Numeric
87 88 89 90 91 |
# File 'TT_Lib2/progressbar.rb', line 87 def value=(new_value) @value = new_value updateUI() @value end |