diff --git a/.ruby-version b/.ruby-version index 227cea2..276cbf9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.0.0 +2.3.0 diff --git a/lib/phone.rb b/lib/phone.rb index e5169e9..99a22d7 100644 --- a/lib/phone.rb +++ b/lib/phone.rb @@ -131,10 +131,9 @@ def self.split_to_parts(string, options = {}) if country options[:country_code] = country.country_code string = string.gsub(country.country_code_regexp, "0") - else - if options[:country_code] - country = Country.find_by_country_code options[:country_code] - end + elsif options[:country_code] + country = Country.find_by_country_code options[:country_code] + string = string.gsub(/^#{Regexp.quote(options[:country_code])}/, '') end if country.nil? diff --git a/test/phone_test.rb b/test/phone_test.rb index 638f366..6ca6aa9 100644 --- a/test/phone_test.rb +++ b/test/phone_test.rb @@ -85,6 +85,15 @@ def test_parse_wont_alter_parameter assert_equal "+1 545-545-5454 ext. 4307", number end + def test_parse_with_country_code_but_without_plus_sign + Phoner::Phone.default_country_code = '385' + + pn = Phoner::Phone.parse '385915125486' + assert pn.number == '5125486' + assert pn.area_code == '91' + assert pn.country_code == '385' + end + def test_parse_short_without_special_characters_without_country Phoner::Phone.default_country_code = nil