Guest User

Untitled

a guest
May 26th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. module Enumerable
  2. def each_with_progress(&block)
  3. out = STDERR
  4. self.each_with_index do |thing,i|
  5. out.print sprintf("%s", makeProgress(i,self.count)) + "\r"
  6. block.call thing
  7. end
  8. nil
  9. end
  10.  
  11. protected
  12. def makeProgress(i, t)
  13. percent = (Float(i) / Float(t)) * 100
  14. percent = (( percent / 1).round * 1).to_i
  15. number_of_bars = percent / 5
  16. progress = ""
  17. for g in 0..number_of_bars do
  18. progress = progress + "="
  19. end
  20. for s in 0..(19 - number_of_bars) do
  21. progress = progress + " "
  22. end
  23. if percent < 10 && percent != 100
  24. progress = progress + " "
  25. end
  26. return percent.to_s + "% |" + progress + "|"
  27. end
  28. end
Add Comment
Please, Sign In to add comment