-
Notifications
You must be signed in to change notification settings - Fork 32
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom units via Unitwise#register #37
Conversation
56c7eae
to
6c0d80d
Compare
The code reads smoothly and the docs are even better. My only question is how user-friendly the failure cases are if say someone tries to specify subtly incorrect params to Unitwise.register(
names: ["finger", "fingers"],
symbol: "馃",
scale: {
value: 1.0,
unit_code: '[foz_us]'
},
property: 'fluid volume'
)
Unitwise::AddRegisterError: "Lol u forgot poland 馃嚨馃嚤. And :primary_code. And :secondary_code."
... stacktrace goes here ...
> Maybe something like that? |
I'm also wondering if you might want to (not now, YAGNI) add a set of |
Ok, thanks for the feedback. I went ahead and added As for listing custom units, we have |
I was wondering if it might be worth implementing some check if unit already exists in the atom list. Maybe by searching for primary/secondary code? In case it exists we should either throw an exception "atom already registered" or just a plain message "atom updated!" in case we want it overridable. |
There have been numerous requests for adding one-off, custom, or unsual units to Unitwise. I've not supported these requests in the past because:
However, there is value in supporting user-defined units. Some domains have legitimate units that don't make sense in UCUM.
This PR supports user-defined units via
Unitwise.register()
. It takes a hash of atom properties. For example, if your app had to measure bourbon in fingers ("three fingers of whiskey, please"):And now you can convert to and from it: