diff --git a/lib/phone.rb b/lib/phone.rb index 978f43f..227cb38 100644 --- a/lib/phone.rb +++ b/lib/phone.rb @@ -242,7 +242,7 @@ def format(fmt) # the default format is "+%c%a%n" def to_s - format(:default) + extension.nil? ? format(:default) : format(:default_with_extension) end # does this number belong to the default country code? diff --git a/test/phone_test.rb b/test/phone_test.rb index 8fa3617..e667ff4 100644 --- a/test/phone_test.rb +++ b/test/phone_test.rb @@ -101,6 +101,12 @@ def test_to_s assert pn.to_s == '+385915125486' end + def test_to_s_with_extension + Phoner::Phone.default_country_code = nil + pn = Phoner::Phone.new '5125486', '91', '385', '111' + assert pn.to_s == '+385915125486x111' + end + def test_to_s_without_country_code Phoner::Phone.default_country_code = '385' pn = Phoner::Phone.new '5125486', '91'