mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Show correct return types for examples [ci skip]
This commit is contained in:
parent
2df891dccd
commit
0a96195119
2 changed files with 108 additions and 108 deletions
|
@ -15,72 +15,72 @@ module ActiveSupport::NumericWithFormat
|
|||
# ==== Examples
|
||||
#
|
||||
# Phone Numbers:
|
||||
# 5551234.to_s(:phone) # => 555-1234
|
||||
# 1235551234.to_s(:phone) # => 123-555-1234
|
||||
# 1235551234.to_s(:phone, area_code: true) # => (123) 555-1234
|
||||
# 1235551234.to_s(:phone, delimiter: ' ') # => 123 555 1234
|
||||
# 1235551234.to_s(:phone, area_code: true, extension: 555) # => (123) 555-1234 x 555
|
||||
# 1235551234.to_s(:phone, country_code: 1) # => +1-123-555-1234
|
||||
# 5551234.to_s(:phone) # => "555-1234"
|
||||
# 1235551234.to_s(:phone) # => "123-555-1234"
|
||||
# 1235551234.to_s(:phone, area_code: true) # => "(123) 555-1234"
|
||||
# 1235551234.to_s(:phone, delimiter: ' ') # => "123 555 1234"
|
||||
# 1235551234.to_s(:phone, area_code: true, extension: 555) # => "(123) 555-1234 x 555"
|
||||
# 1235551234.to_s(:phone, country_code: 1) # => "+1-123-555-1234"
|
||||
# 1235551234.to_s(:phone, country_code: 1, extension: 1343, delimiter: '.')
|
||||
# # => +1.123.555.1234 x 1343
|
||||
# # => "+1.123.555.1234 x 1343"
|
||||
#
|
||||
# Currency:
|
||||
# 1234567890.50.to_s(:currency) # => $1,234,567,890.50
|
||||
# 1234567890.506.to_s(:currency) # => $1,234,567,890.51
|
||||
# 1234567890.506.to_s(:currency, precision: 3) # => $1,234,567,890.506
|
||||
# 1234567890.506.to_s(:currency, locale: :fr) # => 1 234 567 890,51 €
|
||||
# 1234567890.50.to_s(:currency) # => "$1,234,567,890.50"
|
||||
# 1234567890.506.to_s(:currency) # => "$1,234,567,890.51"
|
||||
# 1234567890.506.to_s(:currency, precision: 3) # => "$1,234,567,890.506"
|
||||
# 1234567890.506.to_s(:currency, locale: :fr) # => "1 234 567 890,51 €"
|
||||
# -1234567890.50.to_s(:currency, negative_format: '(%u%n)')
|
||||
# # => ($1,234,567,890.50)
|
||||
# # => "($1,234,567,890.50)"
|
||||
# 1234567890.50.to_s(:currency, unit: '£', separator: ',', delimiter: '')
|
||||
# # => £1234567890,50
|
||||
# # => "£1234567890,50"
|
||||
# 1234567890.50.to_s(:currency, unit: '£', separator: ',', delimiter: '', format: '%n %u')
|
||||
# # => 1234567890,50 £
|
||||
# # => "1234567890,50 £"
|
||||
#
|
||||
# Percentage:
|
||||
# 100.to_s(:percentage) # => 100.000%
|
||||
# 100.to_s(:percentage, precision: 0) # => 100%
|
||||
# 1000.to_s(:percentage, delimiter: '.', separator: ',') # => 1.000,000%
|
||||
# 302.24398923423.to_s(:percentage, precision: 5) # => 302.24399%
|
||||
# 1000.to_s(:percentage, locale: :fr) # => 1 000,000%
|
||||
# 100.to_s(:percentage, format: '%n %') # => 100.000 %
|
||||
# 100.to_s(:percentage) # => "100.000%"
|
||||
# 100.to_s(:percentage, precision: 0) # => "100%"
|
||||
# 1000.to_s(:percentage, delimiter: '.', separator: ',') # => "1.000,000%"
|
||||
# 302.24398923423.to_s(:percentage, precision: 5) # => "302.24399%"
|
||||
# 1000.to_s(:percentage, locale: :fr) # => "1 000,000%"
|
||||
# 100.to_s(:percentage, format: '%n %') # => "100.000 %"
|
||||
#
|
||||
# Delimited:
|
||||
# 12345678.to_s(:delimited) # => 12,345,678
|
||||
# 12345678.05.to_s(:delimited) # => 12,345,678.05
|
||||
# 12345678.to_s(:delimited, delimiter: '.') # => 12.345.678
|
||||
# 12345678.to_s(:delimited, delimiter: ',') # => 12,345,678
|
||||
# 12345678.05.to_s(:delimited, separator: ' ') # => 12,345,678 05
|
||||
# 12345678.05.to_s(:delimited, locale: :fr) # => 12 345 678,05
|
||||
# 12345678.to_s(:delimited) # => "12,345,678"
|
||||
# 12345678.05.to_s(:delimited) # => "12,345,678.05"
|
||||
# 12345678.to_s(:delimited, delimiter: '.') # => "12.345.678"
|
||||
# 12345678.to_s(:delimited, delimiter: ',') # => "12,345,678"
|
||||
# 12345678.05.to_s(:delimited, separator: ' ') # => "12,345,678 05"
|
||||
# 12345678.05.to_s(:delimited, locale: :fr) # => "12 345 678,05"
|
||||
# 98765432.98.to_s(:delimited, delimiter: ' ', separator: ',')
|
||||
# # => 98 765 432,98
|
||||
# # => "98 765 432,98"
|
||||
#
|
||||
# Rounded:
|
||||
# 111.2345.to_s(:rounded) # => 111.235
|
||||
# 111.2345.to_s(:rounded, precision: 2) # => 111.23
|
||||
# 13.to_s(:rounded, precision: 5) # => 13.00000
|
||||
# 389.32314.to_s(:rounded, precision: 0) # => 389
|
||||
# 111.2345.to_s(:rounded, significant: true) # => 111
|
||||
# 111.2345.to_s(:rounded, precision: 1, significant: true) # => 100
|
||||
# 13.to_s(:rounded, precision: 5, significant: true) # => 13.000
|
||||
# 111.234.to_s(:rounded, locale: :fr) # => 111,234
|
||||
# 111.2345.to_s(:rounded) # => "111.235"
|
||||
# 111.2345.to_s(:rounded, precision: 2) # => "111.23"
|
||||
# 13.to_s(:rounded, precision: 5) # => "13.00000"
|
||||
# 389.32314.to_s(:rounded, precision: 0) # => "389"
|
||||
# 111.2345.to_s(:rounded, significant: true) # => "111"
|
||||
# 111.2345.to_s(:rounded, precision: 1, significant: true) # => "100"
|
||||
# 13.to_s(:rounded, precision: 5, significant: true) # => "13.000"
|
||||
# 111.234.to_s(:rounded, locale: :fr) # => "111,234"
|
||||
# 13.to_s(:rounded, precision: 5, significant: true, strip_insignificant_zeros: true)
|
||||
# # => 13
|
||||
# 389.32314.to_s(:rounded, precision: 4, significant: true) # => 389.3
|
||||
# # => "13"
|
||||
# 389.32314.to_s(:rounded, precision: 4, significant: true) # => "389.3"
|
||||
# 1111.2345.to_s(:rounded, precision: 2, separator: ',', delimiter: '.')
|
||||
# # => 1.111,23
|
||||
# # => "1.111,23"
|
||||
#
|
||||
# Human-friendly size in Bytes:
|
||||
# 123.to_s(:human_size) # => 123 Bytes
|
||||
# 1234.to_s(:human_size) # => 1.21 KB
|
||||
# 12345.to_s(:human_size) # => 12.1 KB
|
||||
# 1234567.to_s(:human_size) # => 1.18 MB
|
||||
# 1234567890.to_s(:human_size) # => 1.15 GB
|
||||
# 1234567890123.to_s(:human_size) # => 1.12 TB
|
||||
# 1234567890123456.to_s(:human_size) # => 1.1 PB
|
||||
# 1234567890123456789.to_s(:human_size) # => 1.07 EB
|
||||
# 1234567.to_s(:human_size, precision: 2) # => 1.2 MB
|
||||
# 483989.to_s(:human_size, precision: 2) # => 470 KB
|
||||
# 1234567.to_s(:human_size, precision: 2, separator: ',') # => 1,2 MB
|
||||
# 123.to_s(:human_size) # => "123 Bytes"
|
||||
# 1234.to_s(:human_size) # => "1.21 KB"
|
||||
# 12345.to_s(:human_size) # => "12.1 KB"
|
||||
# 1234567.to_s(:human_size) # => "1.18 MB"
|
||||
# 1234567890.to_s(:human_size) # => "1.15 GB"
|
||||
# 1234567890123.to_s(:human_size) # => "1.12 TB"
|
||||
# 1234567890123456.to_s(:human_size) # => "1.1 PB"
|
||||
# 1234567890123456789.to_s(:human_size) # => "1.07 EB"
|
||||
# 1234567.to_s(:human_size, precision: 2) # => "1.2 MB"
|
||||
# 483989.to_s(:human_size, precision: 2) # => "470 KB"
|
||||
# 1234567.to_s(:human_size, precision: 2, separator: ',') # => "1,2 MB"
|
||||
# 1234567890123.to_s(:human_size, precision: 5) # => "1.1228 TB"
|
||||
# 524288000.to_s(:human_size, precision: 5) # => "500 MB"
|
||||
#
|
||||
|
|
|
@ -29,17 +29,17 @@ module ActiveSupport
|
|||
# number.
|
||||
# ==== Examples
|
||||
#
|
||||
# number_to_phone(5551234) # => 555-1234
|
||||
# number_to_phone('5551234') # => 555-1234
|
||||
# number_to_phone(1235551234) # => 123-555-1234
|
||||
# number_to_phone(1235551234, area_code: true) # => (123) 555-1234
|
||||
# number_to_phone(1235551234, delimiter: ' ') # => 123 555 1234
|
||||
# number_to_phone(1235551234, area_code: true, extension: 555) # => (123) 555-1234 x 555
|
||||
# number_to_phone(1235551234, country_code: 1) # => +1-123-555-1234
|
||||
# number_to_phone('123a456') # => 123a456
|
||||
# number_to_phone(5551234) # => "555-1234"
|
||||
# number_to_phone('5551234') # => "555-1234"
|
||||
# number_to_phone(1235551234) # => "123-555-1234"
|
||||
# number_to_phone(1235551234, area_code: true) # => "(123) 555-1234"
|
||||
# number_to_phone(1235551234, delimiter: ' ') # => "123 555 1234"
|
||||
# number_to_phone(1235551234, area_code: true, extension: 555) # => "(123) 555-1234 x 555"
|
||||
# number_to_phone(1235551234, country_code: 1) # => "+1-123-555-1234"
|
||||
# number_to_phone('123a456') # => "123a456"
|
||||
#
|
||||
# number_to_phone(1235551234, country_code: 1, extension: 1343, delimiter: '.')
|
||||
# # => +1.123.555.1234 x 1343
|
||||
# # => "+1.123.555.1234 x 1343"
|
||||
def number_to_phone(number, options = {})
|
||||
NumberToPhoneConverter.convert(number, options)
|
||||
end
|
||||
|
@ -78,18 +78,18 @@ module ActiveSupport
|
|||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# number_to_currency(1234567890.50) # => $1,234,567,890.50
|
||||
# number_to_currency(1234567890.506) # => $1,234,567,890.51
|
||||
# number_to_currency(1234567890.506, precision: 3) # => $1,234,567,890.506
|
||||
# number_to_currency(1234567890.506, locale: :fr) # => 1 234 567 890,51 €
|
||||
# number_to_currency('123a456') # => $123a456
|
||||
# number_to_currency(1234567890.50) # => "$1,234,567,890.50"
|
||||
# number_to_currency(1234567890.506) # => "$1,234,567,890.51"
|
||||
# number_to_currency(1234567890.506, precision: 3) # => "$1,234,567,890.506"
|
||||
# number_to_currency(1234567890.506, locale: :fr) # => "1 234 567 890,51 €"
|
||||
# number_to_currency('123a456') # => "$123a456"
|
||||
#
|
||||
# number_to_currency(-1234567890.50, negative_format: '(%u%n)')
|
||||
# # => ($1,234,567,890.50)
|
||||
# # => "($1,234,567,890.50)"
|
||||
# number_to_currency(1234567890.50, unit: '£', separator: ',', delimiter: '')
|
||||
# # => £1234567890,50
|
||||
# # => "£1234567890,50"
|
||||
# number_to_currency(1234567890.50, unit: '£', separator: ',', delimiter: '', format: '%n %u')
|
||||
# # => 1234567890,50 £
|
||||
# # => "1234567890,50 £"
|
||||
def number_to_currency(number, options = {})
|
||||
NumberToCurrencyConverter.convert(number, options)
|
||||
end
|
||||
|
@ -118,15 +118,15 @@ module ActiveSupport
|
|||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# number_to_percentage(100) # => 100.000%
|
||||
# number_to_percentage('98') # => 98.000%
|
||||
# number_to_percentage(100, precision: 0) # => 100%
|
||||
# number_to_percentage(1000, delimiter: '.', separator: ',') # => 1.000,000%
|
||||
# number_to_percentage(302.24398923423, precision: 5) # => 302.24399%
|
||||
# number_to_percentage(1000, locale: :fr) # => 1000,000%
|
||||
# number_to_percentage(1000, precision: nil) # => 1000%
|
||||
# number_to_percentage('98a') # => 98a%
|
||||
# number_to_percentage(100, format: '%n %') # => 100.000 %
|
||||
# number_to_percentage(100) # => "100.000%"
|
||||
# number_to_percentage('98') # => "98.000%"
|
||||
# number_to_percentage(100, precision: 0) # => "100%"
|
||||
# number_to_percentage(1000, delimiter: '.', separator: ',') # => "1.000,000%"
|
||||
# number_to_percentage(302.24398923423, precision: 5) # => "302.24399%"
|
||||
# number_to_percentage(1000, locale: :fr) # => "1000,000%"
|
||||
# number_to_percentage(1000, precision: nil) # => "1000%"
|
||||
# number_to_percentage('98a') # => "98a%"
|
||||
# number_to_percentage(100, format: '%n %') # => "100.000 %"
|
||||
def number_to_percentage(number, options = {})
|
||||
NumberToPercentageConverter.convert(number, options)
|
||||
end
|
||||
|
@ -149,19 +149,19 @@ module ActiveSupport
|
|||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# number_to_delimited(12345678) # => 12,345,678
|
||||
# number_to_delimited('123456') # => 123,456
|
||||
# number_to_delimited(12345678.05) # => 12,345,678.05
|
||||
# number_to_delimited(12345678, delimiter: '.') # => 12.345.678
|
||||
# number_to_delimited(12345678, delimiter: ',') # => 12,345,678
|
||||
# number_to_delimited(12345678.05, separator: ' ') # => 12,345,678 05
|
||||
# number_to_delimited(12345678.05, locale: :fr) # => 12 345 678,05
|
||||
# number_to_delimited('112a') # => 112a
|
||||
# number_to_delimited(12345678) # => "12,345,678"
|
||||
# number_to_delimited('123456') # => "123,456"
|
||||
# number_to_delimited(12345678.05) # => "12,345,678.05"
|
||||
# number_to_delimited(12345678, delimiter: '.') # => "12.345.678"
|
||||
# number_to_delimited(12345678, delimiter: ',') # => "12,345,678"
|
||||
# number_to_delimited(12345678.05, separator: ' ') # => "12,345,678 05"
|
||||
# number_to_delimited(12345678.05, locale: :fr) # => "12 345 678,05"
|
||||
# number_to_delimited('112a') # => "112a"
|
||||
# number_to_delimited(98765432.98, delimiter: ' ', separator: ',')
|
||||
# # => 98 765 432,98
|
||||
# # => "98 765 432,98"
|
||||
# number_to_delimited("123456.78",
|
||||
# delimiter_pattern: /(\d+?)(?=(\d\d)+(\d)(?!\d))/)
|
||||
# # => 1,23,456.78
|
||||
# # => "1,23,456.78"
|
||||
def number_to_delimited(number, options = {})
|
||||
NumberToDelimitedConverter.convert(number, options)
|
||||
end
|
||||
|
@ -190,22 +190,22 @@ module ActiveSupport
|
|||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# number_to_rounded(111.2345) # => 111.235
|
||||
# number_to_rounded(111.2345, precision: 2) # => 111.23
|
||||
# number_to_rounded(13, precision: 5) # => 13.00000
|
||||
# number_to_rounded(389.32314, precision: 0) # => 389
|
||||
# number_to_rounded(111.2345, significant: true) # => 111
|
||||
# number_to_rounded(111.2345, precision: 1, significant: true) # => 100
|
||||
# number_to_rounded(13, precision: 5, significant: true) # => 13.000
|
||||
# number_to_rounded(13, precision: nil) # => 13
|
||||
# number_to_rounded(111.234, locale: :fr) # => 111,234
|
||||
# number_to_rounded(111.2345) # => "111.235"
|
||||
# number_to_rounded(111.2345, precision: 2) # => "111.23"
|
||||
# number_to_rounded(13, precision: 5) # => "13.00000"
|
||||
# number_to_rounded(389.32314, precision: 0) # => "389"
|
||||
# number_to_rounded(111.2345, significant: true) # => "111"
|
||||
# number_to_rounded(111.2345, precision: 1, significant: true) # => "100"
|
||||
# number_to_rounded(13, precision: 5, significant: true) # => "13.000"
|
||||
# number_to_rounded(13, precision: nil) # => "13"
|
||||
# number_to_rounded(111.234, locale: :fr) # => "111,234"
|
||||
#
|
||||
# number_to_rounded(13, precision: 5, significant: true, strip_insignificant_zeros: true)
|
||||
# # => 13
|
||||
# # => "13"
|
||||
#
|
||||
# number_to_rounded(389.32314, precision: 4, significant: true) # => 389.3
|
||||
# number_to_rounded(389.32314, precision: 4, significant: true) # => "389.3"
|
||||
# number_to_rounded(1111.2345, precision: 2, separator: ',', delimiter: '.')
|
||||
# # => 1.111,23
|
||||
# # => "1.111,23"
|
||||
def number_to_rounded(number, options = {})
|
||||
NumberToRoundedConverter.convert(number, options)
|
||||
end
|
||||
|
@ -237,17 +237,17 @@ module ActiveSupport
|
|||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# number_to_human_size(123) # => 123 Bytes
|
||||
# number_to_human_size(1234) # => 1.21 KB
|
||||
# number_to_human_size(12345) # => 12.1 KB
|
||||
# number_to_human_size(1234567) # => 1.18 MB
|
||||
# number_to_human_size(1234567890) # => 1.15 GB
|
||||
# number_to_human_size(1234567890123) # => 1.12 TB
|
||||
# number_to_human_size(1234567890123456) # => 1.1 PB
|
||||
# number_to_human_size(1234567890123456789) # => 1.07 EB
|
||||
# number_to_human_size(1234567, precision: 2) # => 1.2 MB
|
||||
# number_to_human_size(483989, precision: 2) # => 470 KB
|
||||
# number_to_human_size(1234567, precision: 2, separator: ',') # => 1,2 MB
|
||||
# number_to_human_size(123) # => "123 Bytes"
|
||||
# number_to_human_size(1234) # => "1.21 KB"
|
||||
# number_to_human_size(12345) # => "12.1 KB"
|
||||
# number_to_human_size(1234567) # => "1.18 MB"
|
||||
# number_to_human_size(1234567890) # => "1.15 GB"
|
||||
# number_to_human_size(1234567890123) # => "1.12 TB"
|
||||
# number_to_human_size(1234567890123456) # => "1.1 PB"
|
||||
# number_to_human_size(1234567890123456789) # => "1.07 EB"
|
||||
# number_to_human_size(1234567, precision: 2) # => "1.2 MB"
|
||||
# number_to_human_size(483989, precision: 2) # => "470 KB"
|
||||
# number_to_human_size(1234567, precision: 2, separator: ',') # => "1,2 MB"
|
||||
# number_to_human_size(1234567890123, precision: 5) # => "1.1228 TB"
|
||||
# number_to_human_size(524288000, precision: 5) # => "500 MB"
|
||||
def number_to_human_size(number, options = {})
|
||||
|
|
Loading…
Reference in a new issue