class Progress

Public Class Methods

new(options = {}) click to toggle source
# File lib/s3_zipper/progress.rb, line 6
def initialize options = {}
  return unless options[:enabled] || true

  @options      = options
  @format       = options[:format]
  @progress_bar = ProgressBar.create(@options)
end

Public Instance Methods

disable() click to toggle source
# File lib/s3_zipper/progress.rb, line 79
def disable
  @progress_bar = nil
end
finish(title: nil, format: nil) click to toggle source
# 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) click to toggle source
# File lib/s3_zipper/progress.rb, line 83
def get_attr attr
  return unless @progress_bar

  @progress_bar.send(attr)
end
increment(attrs = {}) click to toggle source
# 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() click to toggle source
# File lib/s3_zipper/progress.rb, line 36
def percentage
  return unless @progress_bar

  @progress_bar.to_h["percentage"]
end
progress() click to toggle source
# File lib/s3_zipper/progress.rb, line 48
def progress
  return unless @progress_bar

  @progress_bar.progress
end
refresh() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/s3_zipper/progress.rb, line 24
def spin
  until @progress_bar.finished?
    increment
  end
end
total() click to toggle source
# File lib/s3_zipper/progress.rb, line 30
def total
  return unless @progress_bar

  @progress_bar.total
end
update(attr, value) click to toggle source
# 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) click to toggle source
# File lib/s3_zipper/progress.rb, line 61
def update_attrs attrs
  attrs.each(&method(:update))
end