phonelib icon indicating copy to clipboard operation
phonelib copied to clipboard

Only one country is returned in despite multiples matching

Open aisler-ma opened this issue 2 years ago • 1 comments

Hi all together,

awesome library and works pretty good! However, I noticed one issue: if one defines multiple countries to check—either via default values or as parameter—the tool check for all countries where the phone number is valid/possible, however returns only the first valid result. This is okay, if one wants to guess and just want to get one single result. However, it is also kind of confusing, and I have a use case where I want to check if the given number is possible in more than one country.

I also found the responsible line of code: https://github.com/daddyz/phonelib/blob/master/lib/phonelib/phone_analyzer_helper.rb#L12

I was wondering why you do this and/or if there's a way to get a list of all countries where the number is valid*?

Thanks in advance and best!

  • I already tried .countries but it returned only one (the guessed) country.

aisler-ma avatar Nov 29 '23 12:11 aisler-ma

@aisler-ma interesting request, well, take this one as example, it works where there are multiple possibilities:

phone = Phonelib.parse("1 (787) 240-2750")
phone.countries # => ["AG", "AI", "AS", "BB", "BM", "BS", "CA", "DM", "DO", "GD", "GU", "JM", "KN", "KY", "LC", "MP", "MS", "PR", "SX", "TC", "TT", "US", "VC", "VG", "VI"]
phone.valid_countries # => ["PR"]

daddyz avatar Mar 16 '24 18:03 daddyz