From 993bcf34b9335bba7417568b1df7d3a43954b3b3 Mon Sep 17 00:00:00 2001 From: Jeff Felchner Date: Fri, 3 Mar 2023 01:05:42 -0600 Subject: [PATCH] Refactor: The calculate Instance Method Is No Longer Needed Why This Change Is Necessary ======================================================================== This helper method is useless now. What These Changes Do To Address the Issue ======================================================================== Inline the method. Side Effects Caused By This Change ======================================================================== None expected. --- lib/ruby-progressbar/calculators/smoothed_average.rb | 10 +++------- .../calculators/smoothed_average_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/ruby-progressbar/calculators/smoothed_average.rb b/lib/ruby-progressbar/calculators/smoothed_average.rb index fbe365d..ccafc2a 100644 --- a/lib/ruby-progressbar/calculators/smoothed_average.rb +++ b/lib/ruby-progressbar/calculators/smoothed_average.rb @@ -33,22 +33,18 @@ def progress samples[1] end - def progress=(new_progress) - samples[1] = new_progress - calculate(absolute) - end - def total=(_new_total); end def reset start(:at => samples[0]) end - def calculate(new_value) + def progress=(new_progress) + samples[1] = new_progress self.projection = \ self.class.calculate( @projection, - new_value, + absolute, strength ) end diff --git a/spec/lib/ruby-progressbar/calculators/smoothed_average_spec.rb b/spec/lib/ruby-progressbar/calculators/smoothed_average_spec.rb index 6d7264c..942168f 100644 --- a/spec/lib/ruby-progressbar/calculators/smoothed_average_spec.rb +++ b/spec/lib/ruby-progressbar/calculators/smoothed_average_spec.rb @@ -19,7 +19,7 @@ module Calculators it 'resets the projection' do projector = SmoothedAverage.new projector.start - projector.calculate(10) + projector.progress = 10 expect(projector.projection).not_to be_zero @@ -33,7 +33,7 @@ module Calculators it 'resets the projection' do projector = SmoothedAverage.new projector.start - projector.calculate(10) + projector.progress = 10 expect(projector.projection).not_to be_zero