You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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.
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
vsdozen
).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?
The text was updated successfully, but these errors were encountered: