Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Enumerable
- def each_with_progress(&block)
- out = STDERR
- self.each_with_index do |thing,i|
- out.print sprintf("%s", makeProgress(i,self.count)) + "\r"
- 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
Add Comment
Please, Sign In to add comment