Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0
2.3.0
7 changes: 3 additions & 4 deletions lib/phone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
9 changes: 9 additions & 0 deletions test/phone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down