Shopify / measured-rails

Rails adapter for the measured gem. Encapsulate measurements and their units in Ruby and Rails.
MIT License
92 stars 13 forks source link

How to retrieve list of units in use #38

Closed xhocquet closed 7 years ago

xhocquet commented 7 years ago

Hey, I'm looking for an easy way to retrieve a list of units used by the library to use in a collection select. Something like:

collection_select(@grain_store, :store_weight_unit, Measured.UNITS .... )

I looked through the source and didn't see anything clearly public, would there be any interest in adding this?

kmcphillips commented 7 years ago

From the README.md:

See all valid units:

Measured::Weight.unit_names
> ["g", "kg", "lb", "oz"]

See all valid units with their aliases:

Measured::Weight.unit_names_with_aliases
> ["g", "gram", "grams", "kg", "kilogram", "kilograms", "lb", "lbs", "ounce", "ounces", "oz", "pound", "pounds"]

👍