lib/progressbar.rb in narou-1.2.9 vs lib/progressbar.rb in narou-1.3.0

- old
+ new

@@ -2,19 +2,24 @@ # # Copyright 2013 whiteleaf. All rights reserved. # class ProgressBar + class OverRangeError < StandardError; end + def initialize(max, interval = 1, width = 50, char = "*") @max = max == 0 ? 1.0 : max.to_f @interval = interval @width = width @char = char @counter = 0 end def output(num) return if $debug + if num > @max + raise OverRangeError, "`#{num}` over `#{@max}(max)`" + end @counter += 1 return unless @counter % @interval == 0 ratio = calc_ratio(num) now = (@width * ratio).round rest = @width - now