-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Ability To Allow Different Projectors To Be Used For Time Estimates
Why This Change Is Necessary ======================================================================== The current projector we've had in the code for over a decade now has served us well, but there has been a desire to have some different types of projectors (eg windowed by item count or by time). This was previously difficult to do but with this change we should be able to allow the user to swap different ones out fairly easily. What These Changes Do To Address the Issue ======================================================================== Add a new `Projector` class that manages all other projectors. Side Effects Caused By This Change ======================================================================== None expected.
- Loading branch information
Showing
3 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'ruby-progressbar/calculators/smoothed_average' | ||
|
||
class ProgressBar | ||
class Projector | ||
DEFAULT_PROJECTOR = ProgressBar::Calculators::SmoothedAverage | ||
NAME_TO_PROJECTOR_MAP = { | ||
'smoothed' => ProgressBar::Calculators::SmoothedAverage | ||
}.freeze | ||
|
||
def self.from_type(name) | ||
NAME_TO_PROJECTOR_MAP.fetch(name, DEFAULT_PROJECTOR) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'spec_helper' | ||
require 'ruby-progressbar/projector' | ||
|
||
class ProgressBar | ||
describe Projector do | ||
describe '.from_type' do | ||
it 'has a default projector' do | ||
projector = Projector.from_type(nil) | ||
|
||
expect(projector).to be ProgressBar::Calculators::SmoothedAverage | ||
end | ||
|
||
it 'can return a specific projector' do | ||
projector = Projector.from_type('smoothed') | ||
|
||
expect(projector).to be ProgressBar::Calculators::SmoothedAverage | ||
end | ||
end | ||
end | ||
end |