module GetCountryByPhone
Public Instance Methods
get_country_geo_by_phone(phone_number)
click to toggle source
Получить геометрический (географический) центр страны по номеру телефона Если коду страны из номера телефона соответствуют более 1 страны (например, +7 для RU и KZ), то взята будет одна первая страна из списка согласно приоритету countries_priorities.yml
# File lib/ptc/get_country_by_phone.rb, line 8 def get_country_geo_by_phone(phone_number) return nil if phone_number.nil? phone_number = Phony.split(_numeric phone_number) return nil unless phone_number.all? country_code = phone_number[0] countries = ISO3166::Country.find_all_by(:country_code, country_code) top_country = top_priority_country_by_country_code country_code country = top_country.nil? ? countries.values.first : countries[top_country] #gem "countries", '3.0.1' #country_geo = country.values.first['geo'] # OpenStruct.new( # latitude: country_geo['latitude'], # longitude: country_geo['longitude'] # ) #puts [country['latitude_dec'], country['longitude_dec']].join ',' OpenStruct.new( latitude: country['latitude_dec'], longitude: country['longitude_dec'] ) rescue ::Phony::SplittingError nil end