Class: TaskProgressBar
- Inherits:
-
Object
- Object
- TaskProgressBar
- Defined in:
- lib/task_progress_bar.rb,
lib/task_progress_bar/version.rb
Constant Summary collapse
- VERSION =
'1.0.1'
Instance Method Summary collapse
- #bar ⇒ Object
- #bar_quantity ⇒ Object
- #count(value = 1) ⇒ Object
- #elapsed_bar ⇒ Object
- #elapsed_percent ⇒ Object
- #elapsed_time ⇒ Object
- #elapsed_time_formated ⇒ Object
- #green_elapsed_bar ⇒ Object
-
#initialize(total) ⇒ TaskProgressBar
constructor
A new instance of TaskProgressBar.
- #step ⇒ Object
- #symbol ⇒ Object
- #time_formated(value) ⇒ Object
- #time_left ⇒ Object
- #time_left_in_seconds ⇒ Object
- #total_progress ⇒ Object
Constructor Details
#initialize(total) ⇒ TaskProgressBar
Returns a new instance of TaskProgressBar.
4 5 6 7 8 9 |
# File 'lib/task_progress_bar.rb', line 4 def initialize(total) @total = total || 1 = ( total < 50 ? total : 50 ) @start_time = Time.now @i = 0 end |
Instance Method Details
#bar ⇒ Object
16 17 18 |
# File 'lib/task_progress_bar.rb', line 16 def "\r[%d/%d][%s][%d%%][%s][%s]" % [@i, @total, , elapsed_percent, elapsed_time_formated, time_left] end |
#bar_quantity ⇒ Object
32 33 34 |
# File 'lib/task_progress_bar.rb', line 32 def ((@i*1.00/total_progress).to_i) end |
#count(value = 1) ⇒ Object
20 21 22 |
# File 'lib/task_progress_bar.rb', line 20 def count(value = 1) @i += value end |
#elapsed_bar ⇒ Object
40 41 42 |
# File 'lib/task_progress_bar.rb', line 40 def "%-#{@total_bar}s" % [symbol * ] end |
#elapsed_percent ⇒ Object
44 45 46 |
# File 'lib/task_progress_bar.rb', line 44 def elapsed_percent ((@i*1.00/@total)*100).to_i end |
#elapsed_time ⇒ Object
48 49 50 |
# File 'lib/task_progress_bar.rb', line 48 def elapsed_time Time.now - @start_time end |
#elapsed_time_formated ⇒ Object
52 53 54 |
# File 'lib/task_progress_bar.rb', line 52 def elapsed_time_formated time_formated( elapsed_time ) end |
#green_elapsed_bar ⇒ Object
36 37 38 |
# File 'lib/task_progress_bar.rb', line 36 def "\033[32m#{ elapsed_bar }\033[0m" end |
#step ⇒ Object
11 12 13 14 |
# File 'lib/task_progress_bar.rb', line 11 def step self.count STDOUT.print self. end |
#symbol ⇒ Object
24 25 26 |
# File 'lib/task_progress_bar.rb', line 24 def symbol '#' end |
#time_formated(value) ⇒ Object
65 66 67 |
# File 'lib/task_progress_bar.rb', line 65 def time_formated( value ) Time.at( value ).utc.strftime("%H:%M:%S") end |
#time_left ⇒ Object
61 62 63 |
# File 'lib/task_progress_bar.rb', line 61 def time_left time_formated( time_left_in_seconds ) end |
#time_left_in_seconds ⇒ Object
56 57 58 59 |
# File 'lib/task_progress_bar.rb', line 56 def time_left_in_seconds return 0 if @i == 0 ( (elapsed_time / @i) * (@total.to_f - @i) ).to_i end |
#total_progress ⇒ Object
28 29 30 |
# File 'lib/task_progress_bar.rb', line 28 def total_progress @total / end |