Closed Awlexus closed 1 year ago
@Awlexus thanks for the report, and for finding value in the library. Its probably my favourite of the ex_cldr
family :-)
Very reasonable request. I think to differentiate it I will call is something like parse_unit_name/2
to make it clear the result is a name, not a unit struct.
I'm definitely open to a PR but I also know some of this code is quite difficult to understand because of how it is rules driven. I won't be able to get to this until the weekend - hopefully that's ok?
Thanks for the fast reply! parse_unit_name/2
sounds good.
I've already taken a look how Cldr.Unit.parse/2
is implemented and I think it will be straightforward to derive a function that will only parse the unit name from that, so i'll give it a try tomorrow 👍
I've published ex_cldr_units version 3.14.0 with the following changelog entry:
Cldr.Unit.parse_unit_name/2
to parse a string as unit name. Also adds MyApp.Cldr.parse_unit_name/2
as well as the !
versions of these functions. Thanks to @Awlexus for the PR. Closes #31.Thanks for the PR and the collaboration!
I'm trying to parse some user input where the user can only enter the unit without a value, but I couldn't found a function that - similar to
Cldr.Unit.parse/2
- also considers aliases and other forms, like "kg" for "kilogram". Is there I function I might have overlooked? I've tried the following functions, but so far had to settle forCldr.Unit.parse("1" <> "user_input")
to get the unitCldr.Unit.base_unit/1
Cldr.Unit.Parser.parse_unit/1
Cldr.Unit.Parser.canonical_unit_name/1
Edit: If such a function does not exist, would you be open for a PR?