-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Classification of units #17
Comments
There is no context of "unit classification" built into the library, there is only a context of conversion calculation mappings between units. So if a mapping exists between two units, then it will convert using the calculation method provided. Currently, if a calculation method does not exist, then an One possibility would be to add explicit error classes such as |
That sounds really helpful! And it looks like a pretty straightforward change to just add those more specific error classes. Would you like a PR for that? |
That'd be great if you'd like to! One suggestion would be for them to extend ArgumentError so that it doesn't break existing implementations. Thanks! |
I have logic in place to prevent my users from trying to convert between incompatible units. For example: pounds --> gallons. I currently throw an error message, which explains that incompatible unit conversion is probably the issue. But I can't be certain, because the way I'm validating is by simply attempting the conversion and
rescue
ing if it fails:So this same validation error could also occur if a user attempted a nonsense unit. Ex:
37 blrblbs
I'm trying to figure out a way to be even more clear, and say something like:
I suspect that the library is already tracking this classification of units somewhere, but it does not appear to be exposed anywhere in the API? Would this be hard to do?
The text was updated successfully, but these errors were encountered: