Skip to content

Commit 6be13c8

Browse files
Clean up AS::NumberHelper#number_to_phone doc [ci-skip]
1 parent 2945608 commit 6be13c8

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

activesupport/lib/active_support/number_helper.rb

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,51 @@ module NumberHelper
1818

1919
extend self
2020

21-
# Formats a +number+ into a phone number (US by default e.g., (555)
22-
# 123-9876). You can customize the format in the +options+ hash.
21+
# Formats +number+ into a phone number.
22+
#
23+
# number_to_phone(5551234) # => "555-1234"
24+
# number_to_phone("5551234") # => "555-1234"
25+
# number_to_phone(1235551234) # => "123-555-1234"
26+
# number_to_phone("12x34") # => "12x34"
27+
#
28+
# number_to_phone(1235551234, delimiter: ".", country_code: 1, extension: 1343)
29+
# # => "+1.123.555.1234 x 1343"
2330
#
2431
# ==== Options
2532
#
26-
# * <tt>:area_code</tt> - Adds parentheses around the area code.
27-
# * <tt>:delimiter</tt> - Specifies the delimiter to use
28-
# (defaults to "-").
29-
# * <tt>:extension</tt> - Specifies an extension to add to the
30-
# end of the generated number.
31-
# * <tt>:country_code</tt> - Sets the country code for the phone
32-
# number.
33-
# * <tt>:pattern</tt> - Specifies how the number is divided into three
34-
# groups with the custom regexp to override the default format.
35-
# ==== Examples
33+
# [+:area_code+]
34+
# Whether to use parentheses for the area code. Defaults to false.
3635
#
37-
# number_to_phone(5551234) # => "555-1234"
38-
# number_to_phone('5551234') # => "555-1234"
39-
# number_to_phone(1235551234) # => "123-555-1234"
40-
# number_to_phone(1235551234, area_code: true) # => "(123) 555-1234"
41-
# number_to_phone(1235551234, delimiter: ' ') # => "123 555 1234"
42-
# number_to_phone(1235551234, area_code: true, extension: 555) # => "(123) 555-1234 x 555"
43-
# number_to_phone(1235551234, country_code: 1) # => "+1-123-555-1234"
44-
# number_to_phone('123a456') # => "123a456"
36+
# number_to_phone(1235551234, area_code: true)
37+
# # => "(123) 555-1234"
4538
#
46-
# number_to_phone(1235551234, country_code: 1, extension: 1343, delimiter: '.')
47-
# # => "+1.123.555.1234 x 1343"
39+
# [+:delimiter+]
40+
# The digit group delimiter to use. Defaults to <tt>"-"</tt>.
41+
#
42+
# number_to_phone(1235551234, delimiter: " ")
43+
# # => "123 555 1234"
44+
#
45+
# [+:country_code+]
46+
# A country code to prepend.
47+
#
48+
# number_to_phone(1235551234, country_code: 1)
49+
# # => "+1-123-555-1234"
50+
#
51+
# [+:extension+]
52+
# An extension to append.
53+
#
54+
# number_to_phone(1235551234, extension: 555)
55+
# # => "123-555-1234 x 555"
56+
#
57+
# [+:pattern+]
58+
# A regexp that specifies how the digits should be grouped. The first
59+
# three captures from the regexp are treated as digit groups.
60+
#
61+
# number_to_phone(13312345678, pattern: /(\d{3})(\d{4})(\d{4})$/)
62+
# # => "133-1234-5678"
63+
# number_to_phone(75561234567, pattern: /(\d{1,4})(\d{4})(\d{4})$/, area_code: true)
64+
# # => "(755) 6123-4567"
4865
#
49-
# number_to_phone(75561234567, pattern: /(\d{1,4})(\d{4})(\d{4})$/, area_code: true)
50-
# # => "(755) 6123-4567"
51-
# number_to_phone(13312345678, pattern: /(\d{3})(\d{4})(\d{4})$/)
52-
# # => "133-1234-5678"
5366
def number_to_phone(number, options = {})
5467
NumberToPhoneConverter.convert(number, options)
5568
end

0 commit comments

Comments
 (0)