lib/phonelib/phone_analyzer_helper.rb in phonelib-0.8.0 vs lib/phonelib/phone_analyzer_helper.rb in phonelib-0.8.1
- old
+ new
@@ -5,10 +5,12 @@
def decorate_analyze_result(result)
if result.size == 1
result
else
+ matched_countries = country_or_default_country(nil) & result.keys
+ result = result.keep_if {|k, _v| matched_countries.include?(k) } if matched_countries
Hash[result.take(1)]
end
end
def original_starts_with_plus?
@@ -54,19 +56,20 @@
# defines whether country can have double country prefix in number
def country_can_dp?(country)
Phonelib.phone_data[country] &&
Phonelib.phone_data[country][Core::DOUBLE_COUNTRY_PREFIX_FLAG] &&
- !original_starts_with_plus?
+ !original_starts_with_plus? && original_s.start_with?(Phonelib.phone_data[country][Core::COUNTRY_CODE])
end
# changes phone to with/without double country prefix
def changed_dp_phone(country, phone)
data = Phonelib.phone_data[country]
return if data.nil? || data[Core::DOUBLE_COUNTRY_PREFIX_FLAG].nil?
country_code = Phonelib.phone_data[country][Core::COUNTRY_CODE]
if phone.start_with? country_code * 2
+ # remove double prefix in case it is there
phone.gsub(cr("^#{country_code}"), '')
else
"#{country_code}#{phone}"
end
end