Skip to content

Instantly share code, notes, and snippets.

@ktaragorn
Last active March 31, 2016 08:12
Show Gist options
  • Save ktaragorn/b0ce5106b2b8be1c9fffce0af3286e6c to your computer and use it in GitHub Desktop.
Save ktaragorn/b0ce5106b2b8be1c9fffce0af3286e6c to your computer and use it in GitHub Desktop.
A simple progress bar class
class ProgressBar
def initialize max
@max = max
@current = 0.0
end
def draw
progress = @current/@max
wipe = "\r"
bar_length = 20
progress_bar = (progress * bar_length).to_i
bar = "[" + "*" * progress_bar + " " * (bar_length - progress_bar) + "]"
count = "[#{@current}/#{@max}]"
percent = "[#{(progress * 100).to_i} %]"
print wipe, bar, count, percent
end
def increment! by=1
@current += by
@current = @max if @current > @max
draw
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment