Skip to content

Commit 2b801dc

Browse files
Clean up AS::NumberHelper#number_to_human_size doc [ci-skip]
1 parent 8a04207 commit 2b801dc

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

activesupport/lib/active_support/number_helper.rb

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -299,49 +299,55 @@ def number_to_rounded(number, options = {})
299299
NumberToRoundedConverter.convert(number, options)
300300
end
301301

302-
# Formats the bytes in +number+ into a more understandable
303-
# representation (e.g., giving it 1500 yields 1.46 KB). This
304-
# method is useful for reporting file sizes to users. You can
305-
# customize the format in the +options+ hash.
302+
# Formats +number+ as bytes into a more human-friendly representation.
303+
# Useful for reporting file sizes to users.
306304
#
307-
# See <tt>number_to_human</tt> if you want to pretty-print a
308-
# generic number.
305+
# number_to_human_size(123) # => "123 Bytes"
306+
# number_to_human_size(1234) # => "1.21 KB"
307+
# number_to_human_size(12345) # => "12.1 KB"
308+
# number_to_human_size(1234567) # => "1.18 MB"
309+
# number_to_human_size(1234567890) # => "1.15 GB"
310+
# number_to_human_size(1234567890123) # => "1.12 TB"
311+
# number_to_human_size(1234567890123456) # => "1.1 PB"
312+
# number_to_human_size(1234567890123456789) # => "1.07 EB"
313+
#
314+
# See #number_to_human if you want to pretty-print a generic number.
309315
#
310316
# ==== Options
311317
#
312-
# * <tt>:locale</tt> - Sets the locale to be used for formatting
313-
# (defaults to current locale).
314-
# * <tt>:precision</tt> - Sets the precision of the number
315-
# (defaults to 3).
316-
# * <tt>:round_mode</tt> - Determine how rounding is performed
317-
# (defaults to :default. See BigDecimal::mode)
318-
# * <tt>:significant</tt> - If +true+, precision will be the number
319-
# of significant_digits. If +false+, the number of fractional
320-
# digits (defaults to +true+)
321-
# * <tt>:separator</tt> - Sets the separator between the
322-
# fractional and integer digits (defaults to ".").
323-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
324-
# to "").
325-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
326-
# insignificant zeros after the decimal separator (defaults to
327-
# +true+)
318+
# [+:locale+]
319+
# The locale to use for formatting. Defaults to the current locale.
328320
#
329-
# ==== Examples
321+
# [+:precision+]
322+
# The level of precision. Defaults to 3.
323+
#
324+
# number_to_human_size(123456, precision: 2) # => "120 KB"
325+
# number_to_human_size(1234567, precision: 2) # => "1.2 MB"
326+
#
327+
# [+:round_mode+]
328+
# Specifies how rounding is performed. See +BigDecimal.mode+. Defaults to
329+
# +:default+.
330+
#
331+
# number_to_human_size(123456, precision: 2, round_mode: :up)
332+
# # => "130 KB"
333+
#
334+
# [+:significant+]
335+
# Whether +:precision+ should be applied to significant digits instead of
336+
# fractional digits. Defaults to true.
337+
#
338+
# [+:separator+]
339+
# The decimal separator. Defaults to <tt>"."</tt>.
340+
#
341+
# number_to_human_size(1234567, separator: ",")
342+
# # => "1,18 MB"
343+
#
344+
# [+:delimiter+]
345+
# The thousands delimiter. Defaults to <tt>","</tt>.
346+
#
347+
# [+:strip_insignificant_zeros+]
348+
# Whether to remove insignificant zeros after the decimal separator.
349+
# Defaults to true.
330350
#
331-
# number_to_human_size(123) # => "123 Bytes"
332-
# number_to_human_size(1234) # => "1.21 KB"
333-
# number_to_human_size(12345) # => "12.1 KB"
334-
# number_to_human_size(1234567) # => "1.18 MB"
335-
# number_to_human_size(1234567890) # => "1.15 GB"
336-
# number_to_human_size(1234567890123) # => "1.12 TB"
337-
# number_to_human_size(1234567890123456) # => "1.1 PB"
338-
# number_to_human_size(1234567890123456789) # => "1.07 EB"
339-
# number_to_human_size(1234567, precision: 2) # => "1.2 MB"
340-
# number_to_human_size(483989, precision: 2) # => "470 KB"
341-
# number_to_human_size(483989, precision: 2, round_mode: :up) # => "480 KB"
342-
# number_to_human_size(1234567, precision: 2, separator: ',') # => "1,2 MB"
343-
# number_to_human_size(1234567890123, precision: 5) # => "1.1228 TB"
344-
# number_to_human_size(524288000, precision: 5) # => "500 MB"
345351
def number_to_human_size(number, options = {})
346352
NumberToHumanSizeConverter.convert(number, options)
347353
end

0 commit comments

Comments
 (0)