Skip to content

Instantly share code, notes, and snippets.

@JustSnow
Created July 3, 2014 11:02
Show Gist options
  • Save JustSnow/b10b443295ecccd200f9 to your computer and use it in GitHub Desktop.
Save JustSnow/b10b443295ecccd200f9 to your computer and use it in GitHub Desktop.
ProgressBar
module ProgressBar
class << self
def progress_bar(items_count, current_item_index, prefix)
@@start_time = Time.now if current_item_index == 0
time = Time.now - @@start_time
progress = current_item_index.next.to_f / items_count.to_f * 100
bar = "▓" * ( 50 * (progress / 100 ) ).floor
minutes = ((time / progress) * (100 - progress) / 60).round
left_str = "#{minutes} minutes left "
"#{ prefix } ├#{ bar.ljust 50 }┤#{ (progress.round(1).to_s + "%").rjust(6).red } (#{ current_item_index.next } of #{ items_count }) #{ left_str }\r"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment