Class: Progress
- Inherits:
-
Object
- Object
- Progress
- Defined in:
- lib/s3_zipper/progress.rb
Instance Method Summary collapse
- #disable ⇒ Object
- #finish(title: nil, format: nil) ⇒ Object
- #get_attr(attr) ⇒ Object
- #increment(attrs = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Progress
constructor
A new instance of Progress.
- #percentage ⇒ Object
- #progress ⇒ Object
- #refresh ⇒ Object
- #reset(title: nil, total: nil, format: nil) ⇒ Object
- #spin ⇒ Object
- #total ⇒ Object
- #update(attr, value) ⇒ Object
- #update_attrs(attrs) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Progress
Returns a new instance of Progress.
6 7 8 9 10 11 12 |
# File 'lib/s3_zipper/progress.rb', line 6 def initialize = {} return unless [:enabled] || true @options = @format = [:format] @progress_bar = ProgressBar.create(@options) end |
Instance Method Details
#disable ⇒ Object
79 80 81 |
# File 'lib/s3_zipper/progress.rb', line 79 def disable @progress_bar = nil end |
#finish(title: nil, format: nil) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/s3_zipper/progress.rb', line 71 def finish title: nil, format: nil return unless @progress_bar @progress_bar.title = title if title @progress_bar.format = format if format @progress_bar.finish end |
#get_attr(attr) ⇒ Object
83 84 85 86 87 |
# File 'lib/s3_zipper/progress.rb', line 83 def get_attr attr return unless @progress_bar @progress_bar.send(attr) end |
#increment(attrs = {}) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/s3_zipper/progress.rb', line 54 def increment attrs = {} return unless @progress_bar @progress_bar.increment update_attrs(attrs) unless attrs.empty? end |
#percentage ⇒ Object
36 37 38 39 40 |
# File 'lib/s3_zipper/progress.rb', line 36 def percentage return unless @progress_bar @progress_bar.to_h["percentage"] end |
#progress ⇒ Object
48 49 50 51 52 |
# File 'lib/s3_zipper/progress.rb', line 48 def progress return unless @progress_bar @progress_bar.progress end |
#refresh ⇒ Object
42 43 44 45 46 |
# File 'lib/s3_zipper/progress.rb', line 42 def refresh return unless @progress_bar @progress_bar.refresh end |
#reset(title: nil, total: nil, format: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/s3_zipper/progress.rb', line 14 def reset title: nil, total: nil, format: nil return unless @progress_bar @progress_bar.progress = 0 @progress_bar.title = title if title @progress_bar.total = total if total @progress_bar.format = format if format refresh end |
#spin ⇒ Object
24 25 26 27 28 |
# File 'lib/s3_zipper/progress.rb', line 24 def spin until @progress_bar.finished? increment end end |
#total ⇒ Object
30 31 32 33 34 |
# File 'lib/s3_zipper/progress.rb', line 30 def total return unless @progress_bar @progress_bar.total end |
#update(attr, value) ⇒ Object
65 66 67 68 69 |
# File 'lib/s3_zipper/progress.rb', line 65 def update attr, value return unless @progress_bar @progress_bar.send("#{attr}=", value) end |
#update_attrs(attrs) ⇒ Object
61 62 63 |
# File 'lib/s3_zipper/progress.rb', line 61 def update_attrs attrs attrs.each(&method(:update)) end |