Skip to content
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

User-faceing list of units #18

Open
emersonthis opened this issue Jul 18, 2019 · 1 comment
Open

User-faceing list of units #18

emersonthis opened this issue Jul 18, 2019 · 1 comment

Comments

@emersonthis
Copy link

Right now we can get a big list of every unit name with Measurement::Unit.names. Is there a way to do the same thing, but without all the aliases for each? The use case I'm thinking about is a form with a <select> (or whatever) for selecting the units. It would be nice to filter out the repeats (ex: doz vs dozen).

I'm pretty sure I could theoretically simulate this by looping over the entire list and testing conversions between each combination to "reverse-engineer" aliases... but that'd be expensive and messy. Is there a cleaner way to do this? Or perhaps we could add another static method to the class?

@emersonthis
Copy link
Author

Just had another thought on this, related to #17

If we did add another method, ex Measurement::Unit.short_names (or maybe optional arguments to the existing one) it would be really powerful if there was a way to limit the returned list to specific compatibility groups. Something like Measurement::Unit.names(convertable_from: :lbs) which would give you a human-readable list of each unit that has a conversion mapping to pounds.

It would be for the same use case described here and on the other issue: a form where a user selects a unit, but within a specific context where invalid/incompatible units wouldn't make sense. Like if an Ingredient is associated with a Food record. If the Food is measured by liters, you wouldn't want to offer pounds as a measurement option for the Ingredient record.

Just an idea. Maybe for later ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant