Ruby's equivalent of libphonenumber findNumbers

882 views Asked by At

Being aware of these two gems for dealing with phone:

  1. https://github.com/daddyz/phonelib
  2. https://github.com/sstephenson/global_phone

But none of them seems to implement the findNumbers method present in the original lib.

public java.lang.Iterable<PhoneNumberMatch> findNumbers(java.lang.CharSequence text,
                                                        java.lang.String defaultRegion)

So is there any alternative in Ruby, to parse a string an extract the phone number from a given text?

My first though was to use an Regex, but it will fail to deal with different countries an different representations.

The phone number could be from any country, although I know what country the numbers belong, before parsing.

1

There are 1 answers

0
James Daniels On

You could scan a string using phonelib's full_valid_regex_for_data