I have an international number as a string, so 81312345678 (Japan, Tokyo number) or 85212345678 (Hong Kong) and I need to isolate the country code, 81 in the case of Japan and 852 in the case of Hong Kong, in order to then identify the 2 letter alpha2 code of the country.
I have tried the phony gem as follows:
number = Phony.format('18091231234', :format => :international) puts number split = Phony.split('85212345678') puts split
In the case of Hong Kong, for example, I would now like to take '852' and get the 2 letter country code for Hong Kong in order to then look up pricing using the Plivo api.
+1 809 123 1234 852
I have tried the 'iso_country_codes' gem unsuccessfully and the 'countries' gem with:
c = Country.find_country_by_national_prefix('852') puts c.alpha2
The error message is
'undefined method alpha2' this should be easy. Any ideas guys? Thanks as always.