diff --git a/lib/progress_bar.rb b/lib/progress_bar.rb index 0b1c331..23da27b 100644 --- a/lib/progress_bar.rb +++ b/lib/progress_bar.rb @@ -30,10 +30,10 @@ def initialize(*args) def increment!(count = 1) @count += count now = ::Time.now - if (now - @last_write) > 0.2 || @count >= max - write - @last_write = now - end + return unless (now - @last_write) > 0.2 || @count >= max + + write + @last_write = now end def puts(text) @@ -93,7 +93,7 @@ def print(str) end def clear! - print "\r" + " " * terminal_width + "\r" + print "\r" + (" " * terminal_width) + "\r" end def render(meter) @@ -152,12 +152,13 @@ def bar_width def non_bar_width meters.reject { |meter| meter == :bar }.inject(0) do |width, meter| - width += width_of(meter) + 1 + width + width_of(meter) + 1 end end - def counter_width # [ 1/100] - max_width * 2 + 3 + # [ 1/100] + def counter_width + (max_width * 2) + 3 end def percentage_width @@ -176,7 +177,8 @@ def eta_width format_interval(eta).length + 2 end - def rate_width # [ 23.45/s] + # [ 23.45/s] + def rate_width render_rate.length end diff --git a/spec/with_progress_spec.rb b/spec/with_progress_spec.rb index b92b332..b87737c 100644 --- a/spec/with_progress_spec.rb +++ b/spec/with_progress_spec.rb @@ -30,7 +30,7 @@ it "should give Enumerator" do enum = (1..20).each_with_progress - expect(enum).to be_kind_of(Enumerator) + expect(enum).to be_a(Enumerator) expect(bar.max).to eq 20 expect(bar.count).to eq 0