refactor the Converters module
#37
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Very much in the same vein as the refactor in #29 this small PR makes the two "converter" lookups (for
factorandoffsetrespectively) slightly more idiomatic and - arguably - a tad simpler: instead of usingHash#[]it now usesHash#fetchwith - where appropriate - meaningful defaults.To verify that this refactor is functionally equivalent to the original implementation, I have also included some specs for the
Convertersmodule, which all run "green" on both the master branch, as well as on the feature branch for this pull request.The new implementation also avoids superfluous hash lookups: first to test the error conditions, and then exactly the same lookups again to get the actual conversion factor or conversion offset ... this now happens in one go.
The only (minor?) difference introduced by this PR is the wording of the two error messages that are logged when a lookup error occurs, which can be illustrated with:
The first lookup error message changes as follows:
... and the second one as follows:
... but as far as I can tell this is pretty much inconsequential 🤞
Thanks, @scrapper! 🙏