Closed dracos closed 6 years ago
The coverage drop is because every entry in the XML provides a format
, but I left in the else
code in case it did not. If it's okay to assume all entries will do so, then the else
code can be dropped and that section simplified.
Now removed the 'else' case. I've defaulted to intlFormat given format()
outputs with a +countycode, but note a few intlFormat
s are NA
as they can't be called internationally. I don't know if you'd like something different done about them, but it does at least mean it won't output a number that wouldn't work (I imagine these are quite edge case anyway).
For #79 I'll work on adding separate new format_national and format_international functions to keep that independent.
Sorry for taking ages to get back to you on this, Real Life intervened and then I massively slacked off over Christmas and New Year. I like the idea of storing the nationally preferred representation of a number and making it available. However, the format()
method is documented as returning a number in E.123 format - see all the examples in section 2 of the standard. I think this would best be implemented as a formatter - see Number::Phone::Formatters and Number::Phone::Formatter::Raw for an example.
If this could be reworked into something like Number::Phone::Formatter::NationallyPreferred I'd be happy to merge it.
Okay, I've done that, it seems to work okay. I had to pass the object into the formatter, but kept the string argument for backwards compatibility, dos that make sense?
For the other PR that then depends upon this one (national formatting), I can add another formatter to return the national formatted number (Number::Phone::Formatter::National
?), if that is okay with you, but I can't see how I can do the "pass in a country and have it pick national/international as appropriate", so that could instead be a utility function somewhere? It does seem like an obvious thing to want. Update: I've done that.
Thanks!
This stores the format/intlFormat given for each libphonenumber formatter in the stub country files, and adds a new NationallyPreferred formatter to use that infomation.
Fixes #78.