Permalink
Browse files

Merge pull request #3314 from macmartine/master

Remove user-specified delimiter from start when no area code is present (in number_to_phone)
  • Loading branch information...
2 parents 8cbe826 + 20728f5 commit a5b0f914f16aac806a157dd4b6f3e3f3656d8396 @spastorino spastorino committed Oct 13, 2011
@@ -69,7 +69,7 @@ def number_to_phone(number, options = {})
number.gsub!(/(\d{1,3})(\d{3})(\d{4}$)/,"(\\1) \\2#{delimiter}\\3")
else
number.gsub!(/(\d{0,3})(\d{3})(\d{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3")
- number.slice!(0, 1) if number.starts_with?('-')
+ number.slice!(0, 1) if number.starts_with?(delimiter) && !delimiter.blank?
end
str = []
@@ -27,6 +27,7 @@ def test_number_to_phone
assert_equal("800 555 1212", number_to_phone(8005551212, {:delimiter => " "}))
assert_equal("(800) 555-1212 x 123", number_to_phone(8005551212, {:area_code => true, :extension => 123}))
assert_equal("800-555-1212", number_to_phone(8005551212, :extension => " "))
+ assert_equal("555.1212", number_to_phone(5551212, :delimiter => '.'))
assert_equal("800-555-1212", number_to_phone("8005551212"))
assert_equal("+1-800-555-1212", number_to_phone(8005551212, :country_code => 1))
assert_equal("+18005551212", number_to_phone(8005551212, :country_code => 1, :delimiter => ''))

0 comments on commit a5b0f91

Please sign in to comment.