lib/fortschritt/meter.rb in fortschritt-1.0.0 vs lib/fortschritt/meter.rb in fortschritt-1.0.1
- old
+ new
@@ -7,19 +7,20 @@
@done = 0
@updated_at = Time.now
@average_seconds = 0
@started_at = Time.now
@silent = silent || !!(Rails.env.test? if defined?(Rails))
+ @printed_at = Time.now
end
def increment
@_now = Time.now
elapsed_seconds = @_now - updated_at
@average_seconds = calculate_average_seconds(elapsed_seconds)
@updated_at = @_now
@done += 1
- print! unless @silent
+ print! unless @silent || debounce?
end
def completed?
done >= total
end
@@ -41,8 +42,15 @@
Time.now - @started_at
end
def print!
Fortschritt.printer.print(self)
+ end
+
+ def debounce?
+ return true if @updated_at - @printed_at < 0.01 && !completed?
+
+ @printed_at = @updated_at
+ false
end
end
end