Created
May 27, 2010 20:46
-
-
Save adamgamble/416317 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Enumerable | |
def each_with_progress(&block) | |
self.each_with_index do |thing,i| | |
puts makeProgress(i,self.count) | |
block.call thing | |
end | |
nil | |
end | |
protected | |
def makeProgress(i, t) | |
percent = (Float(i) / Float(t)) * 100 | |
percent = (( percent / 1).round * 1).to_i | |
number_of_bars = percent / 5 | |
progress = "" | |
for g in 0..number_of_bars do | |
progress = progress + "=" | |
end | |
for s in 0..(19 - number_of_bars) do | |
progress = progress + " " | |
end | |
if percent < 10 && percent != 100 | |
progress = progress + " " | |
end | |
return percent.to_s + "% |" + progress + "|" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment