Skip to content
This repository
Browse code

Fix NumberHelper options wrapping to prevent verbatim blocks being re…

…ndered instead of line continuations. While I'm at it, wrap long comment lines consistently.
  • Loading branch information...
commit e8c9aeca4e054a365d2b64f542617a40f656c666 1 parent a9c27e7
Mark J. Titorenko mjtko authored

Showing 1 changed file with 161 additions and 92 deletions. Show diff stats Hide diff stats

  1. +161 92 actionpack/lib/action_view/helpers/number_helper.rb
253 actionpack/lib/action_view/helpers/number_helper.rb
@@ -28,17 +28,20 @@ def initialize(number)
28 28 end
29 29 end
30 30
31   - # Formats a +number+ into a US phone number (e.g., (555) 123-9876). You can customize the format
32   - # in the +options+ hash.
  31 + # Formats a +number+ into a US phone number (e.g., (555)
  32 + # 123-9876). You can customize the format in the +options+ hash.
33 33 #
34 34 # ==== Options
35 35 #
36   - # * <tt>:area_code</tt> - Adds parentheses around the area code.
37   - # * <tt>:delimiter</tt> - Specifies the delimiter to use (defaults to "-").
38   - # * <tt>:extension</tt> - Specifies an extension to add to the end of the
39   - # generated number.
40   - # * <tt>:country_code</tt> - Sets the country code for the phone number.
41   - # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when the argument is invalid.
  36 + # * <tt>:area_code</tt> - Adds parentheses around the area code.
  37 + # * <tt>:delimiter</tt> - Specifies the delimiter to use
  38 + # (defaults to "-").
  39 + # * <tt>:extension</tt> - Specifies an extension to add to the
  40 + # end of the generated number.
  41 + # * <tt>:country_code</tt> - Sets the country code for the phone
  42 + # number.
  43 + # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
  44 + # the argument is invalid.
42 45 #
43 46 # ==== Examples
44 47 #
@@ -81,24 +84,31 @@ def number_to_phone(number, options = {})
81 84 ERB::Util.html_escape(str)
82 85 end
83 86
84   - # Formats a +number+ into a currency string (e.g., $13.65). You can customize the format
85   - # in the +options+ hash.
  87 + # Formats a +number+ into a currency string (e.g., $13.65). You
  88 + # can customize the format in the +options+ hash.
86 89 #
87 90 # ==== Options
88 91 #
89   - # * <tt>:locale</tt> - Sets the locale to be used for formatting (defaults to current locale).
90   - # * <tt>:precision</tt> - Sets the level of precision (defaults to 2).
91   - # * <tt>:unit</tt> - Sets the denomination of the currency (defaults to "$").
92   - # * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
93   - # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to ",").
94   - # * <tt>:format</tt> - Sets the format for non-negative numbers (defaults to "%u%n").
95   - # Fields are <tt>%u</tt> for the currency, and <tt>%n</tt>
96   - # for the number.
97   - # * <tt>:negative_format</tt> - Sets the format for negative numbers (defaults to prepending
98   - # an hyphen to the formatted number given by <tt>:format</tt>).
99   - # Accepts the same fields than <tt>:format</tt>, except
100   - # <tt>%n</tt> is here the absolute value of the number.
101   - # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when the argument is invalid.
  92 + # * <tt>:locale</tt> - Sets the locale to be used for formatting
  93 + # (defaults to current locale).
  94 + # * <tt>:precision</tt> - Sets the level of precision (defaults
  95 + # to 2).
  96 + # * <tt>:unit</tt> - Sets the denomination of the currency
  97 + # (defaults to "$").
  98 + # * <tt>:separator</tt> - Sets the separator between the units
  99 + # (defaults to ".").
  100 + # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
  101 + # to ",").
  102 + # * <tt>:format</tt> - Sets the format for non-negative numbers
  103 + # (defaults to "%u%n"). Fields are <tt>%u</tt> for the
  104 + # currency, and <tt>%n</tt> for the number.
  105 + # * <tt>:negative_format</tt> - Sets the format for negative
  106 + # numbers (defaults to prepending an hyphen to the formatted
  107 + # number given by <tt>:format</tt>). Accepts the same fields
  108 + # than <tt>:format</tt>, except <tt>%n</tt> is here the
  109 + # absolute value of the number.
  110 + # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
  111 + # the argument is invalid.
102 112 #
103 113 # ==== Examples
104 114 #
@@ -148,23 +158,29 @@ def number_to_currency(number, options = {})
148 158 end
149 159 end
150 160
151   - # Formats a +number+ as a percentage string (e.g., 65%). You can customize the format in the +options+ hash.
  161 + # Formats a +number+ as a percentage string (e.g., 65%). You can
  162 + # customize the format in the +options+ hash.
152 163 #
153 164 # ==== Options
154 165 #
155   - # * <tt>:locale</tt> - Sets the locale to be used for formatting (defaults to current
156   - # locale).
157   - # * <tt>:precision</tt> - Sets the precision of the number (defaults to 3).
158   - # * <tt>:significant</tt> - If +true+, precision will be the # of significant_digits. If +false+,
159   - # the # of fractional digits (defaults to +false+).
160   - # * <tt>:separator</tt> - Sets the separator between the fractional and integer digits (defaults
161   - # to ".").
162   - # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
163   - # * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator
164   - # (defaults to +false+).
165   - # * <tt>:format</tt> - Specifies the format of the percentage string
166   - # The number field is <tt>%n</tt> (defaults to "%n%").
167   - # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when the argument is invalid.
  166 + # * <tt>:locale</tt> - Sets the locale to be used for formatting
  167 + # (defaults to current locale).
  168 + # * <tt>:precision</tt> - Sets the precision of the number
  169 + # (defaults to 3).
  170 + # * <tt>:significant</tt> - If +true+, precision will be the #
  171 + # of significant_digits. If +false+, the # of fractional
  172 + # digits (defaults to +false+).
  173 + # * <tt>:separator</tt> - Sets the separator between the
  174 + # fractional and integer digits (defaults to ".").
  175 + # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
  176 + # to "").
  177 + # * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
  178 + # insignificant zeros after the decimal separator (defaults to
  179 + # +false+).
  180 + # * <tt>:format</tt> - Specifies the format of the percentage
  181 + # string The number field is <tt>%n</tt> (defaults to "%n%").
  182 + # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
  183 + # the argument is invalid.
168 184 #
169 185 # ==== Examples
170 186 #
@@ -200,15 +216,20 @@ def number_to_percentage(number, options = {})
200 216 end
201 217 end
202 218
203   - # Formats a +number+ with grouped thousands using +delimiter+ (e.g., 12,324). You can
204   - # customize the format in the +options+ hash.
  219 + # Formats a +number+ with grouped thousands using +delimiter+
  220 + # (e.g., 12,324). You can customize the format in the +options+
  221 + # hash.
205 222 #
206 223 # ==== Options
207 224 #
208   - # * <tt>:locale</tt> - Sets the locale to be used for formatting (defaults to current locale).
209   - # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to ",").
210   - # * <tt>:separator</tt> - Sets the separator between the fractional and integer digits (defaults to ".").
211   - # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when the argument is invalid.
  225 + # * <tt>:locale</tt> - Sets the locale to be used for formatting
  226 + # (defaults to current locale).
  227 + # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
  228 + # to ",").
  229 + # * <tt>:separator</tt> - Sets the separator between the
  230 + # fractional and integer digits (defaults to ".").
  231 + # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
  232 + # the argument is invalid.
212 233 #
213 234 # ==== Examples
214 235 #
@@ -236,23 +257,32 @@ def number_with_delimiter(number, options = {})
236 257 safe_join(parts, options[:separator])
237 258 end
238 259
239   - # Formats a +number+ with the specified level of <tt>:precision</tt> (e.g., 112.32 has a precision
240   - # of 2 if +:significant+ is +false+, and 5 if +:significant+ is +true+).
  260 + # Formats a +number+ with the specified level of
  261 + # <tt>:precision</tt> (e.g., 112.32 has a precision of 2 if
  262 + # +:significant+ is +false+, and 5 if +:significant+ is +true+).
241 263 # You can customize the format in the +options+ hash.
242 264 #
243 265 # ==== Options
244   - # * <tt>:locale</tt> - Sets the locale to be used for formatting (defaults to current locale).
245   - # * <tt>:precision</tt> - Sets the precision of the number (defaults to 3).
246   - # * <tt>:significant</tt> - If +true+, precision will be the # of significant_digits. If +false+,
247   - # the # of fractional digits (defaults to +false+).
248   - # * <tt>:separator</tt> - Sets the separator between the fractional and integer digits (defaults
249   - # to ".").
250   - # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
251   - # * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator
252   - # (defaults to +false+).
253   - # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when the argument is invalid.
  266 + #
  267 + # * <tt>:locale</tt> - Sets the locale to be used for formatting
  268 + # (defaults to current locale).
  269 + # * <tt>:precision</tt> - Sets the precision of the number
  270 + # (defaults to 3).
  271 + # * <tt>:significant</tt> - If +true+, precision will be the #
  272 + # of significant_digits. If +false+, the # of fractional
  273 + # digits (defaults to +false+).
  274 + # * <tt>:separator</tt> - Sets the separator between the
  275 + # fractional and integer digits (defaults to ".").
  276 + # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
  277 + # to "").
  278 + # * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
  279 + # insignificant zeros after the decimal separator (defaults to
  280 + # +false+).
  281 + # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
  282 + # the argument is invalid.
254 283 #
255 284 # ==== Examples
  285 + #
256 286 # number_with_precision(111.2345) # => 111.235
257 287 # number_with_precision(111.2345, :precision => 2) # => 111.23
258 288 # number_with_precision(13, :precision => 5) # => 13.00000
@@ -305,23 +335,37 @@ def number_with_precision(number, options = {})
305 335
306 336 STORAGE_UNITS = [:byte, :kb, :mb, :gb, :tb].freeze
307 337
308   - # Formats the bytes in +number+ into a more understandable representation
309   - # (e.g., giving it 1500 yields 1.5 KB). This method is useful for
310   - # reporting file sizes to users. You can customize the
311   - # format in the +options+ hash.
  338 + # Formats the bytes in +number+ into a more understandable
  339 + # representation (e.g., giving it 1500 yields 1.5 KB). This
  340 + # method is useful for reporting file sizes to users. You can
  341 + # customize the format in the +options+ hash.
312 342 #
313   - # See <tt>number_to_human</tt> if you want to pretty-print a generic number.
  343 + # See <tt>number_to_human</tt> if you want to pretty-print a
  344 + # generic number.
314 345 #
315 346 # ==== Options
316   - # * <tt>:locale</tt> - Sets the locale to be used for formatting (defaults to current locale).
317   - # * <tt>:precision</tt> - Sets the precision of the number (defaults to 3).
318   - # * <tt>:significant</tt> - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +true+)
319   - # * <tt>:separator</tt> - Sets the separator between the fractional and integer digits (defaults to ".").
320   - # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
321   - # * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+)
322   - # * <tt>:prefix</tt> - If +:si+ formats the number using the SI prefix (defaults to :binary)
323   - # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when the argument is invalid.
  347 + #
  348 + # * <tt>:locale</tt> - Sets the locale to be used for formatting
  349 + # (defaults to current locale).
  350 + # * <tt>:precision</tt> - Sets the precision of the number
  351 + # (defaults to 3).
  352 + # * <tt>:significant</tt> - If +true+, precision will be the #
  353 + # of significant_digits. If +false+, the # of fractional
  354 + # digits (defaults to +true+)
  355 + # * <tt>:separator</tt> - Sets the separator between the
  356 + # fractional and integer digits (defaults to ".").
  357 + # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
  358 + # to "").
  359 + # * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
  360 + # insignificant zeros after the decimal separator (defaults to
  361 + # +true+)
  362 + # * <tt>:prefix</tt> - If +:si+ formats the number using the SI
  363 + # prefix (defaults to :binary)
  364 + # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
  365 + # the argument is invalid.
  366 + #
324 367 # ==== Examples
  368 + #
325 369 # number_to_human_size(123) # => 123 Bytes
326 370 # number_to_human_size(1234) # => 1.21 KB
327 371 # number_to_human_size(12345) # => 12.1 KB
@@ -332,8 +376,10 @@ def number_with_precision(number, options = {})
332 376 # number_to_human_size(483989, :precision => 2) # => 470 KB
333 377 # number_to_human_size(1234567, :precision => 2, :separator => ',') # => 1,2 MB
334 378 #
335   - # Non-significant zeros after the fractional separator are stripped out by default (set
336   - # <tt>:strip_insignificant_zeros</tt> to +false+ to change that):
  379 + # Non-significant zeros after the fractional separator are
  380 + # stripped out by default (set
  381 + # <tt>:strip_insignificant_zeros</tt> to +false+ to change
  382 + # that):
337 383 # number_to_human_size(1234567890123, :precision => 5) # => "1.1229 TB"
338 384 # number_to_human_size(524288000, :precision => 5) # => "500 MB"
339 385 def number_to_human_size(number, options = {})
@@ -371,33 +417,55 @@ def number_to_human_size(number, options = {})
371 417 DECIMAL_UNITS = {0 => :unit, 1 => :ten, 2 => :hundred, 3 => :thousand, 6 => :million, 9 => :billion, 12 => :trillion, 15 => :quadrillion,
372 418 -1 => :deci, -2 => :centi, -3 => :mili, -6 => :micro, -9 => :nano, -12 => :pico, -15 => :femto}.freeze
373 419
374   - # Pretty prints (formats and approximates) a number in a way it is more readable by humans
375   - # (eg.: 1200000000 becomes "1.2 Billion"). This is useful for numbers that
376   - # can get very large (and too hard to read).
  420 + # Pretty prints (formats and approximates) a number in a way it
  421 + # is more readable by humans (eg.: 1200000000 becomes "1.2
  422 + # Billion"). This is useful for numbers that can get very large
  423 + # (and too hard to read).
377 424 #
378   - # See <tt>number_to_human_size</tt> if you want to print a file size.
  425 + # See <tt>number_to_human_size</tt> if you want to print a file
  426 + # size.
379 427 #
380   - # You can also define you own unit-quantifier names if you want to use other decimal units
381   - # (eg.: 1500 becomes "1.5 kilometers", 0.150 becomes "150 milliliters", etc). You may define
382   - # a wide range of unit quantifiers, even fractional ones (centi, deci, mili, etc).
  428 + # You can also define you own unit-quantifier names if you want
  429 + # to use other decimal units (eg.: 1500 becomes "1.5
  430 + # kilometers", 0.150 becomes "150 milliliters", etc). You may
  431 + # define a wide range of unit quantifiers, even fractional ones
  432 + # (centi, deci, mili, etc).
383 433 #
384 434 # ==== Options
385   - # * <tt>:locale</tt> - Sets the locale to be used for formatting (defaults to current locale).
386   - # * <tt>:precision</tt> - Sets the precision of the number (defaults to 3).
387   - # * <tt>:significant</tt> - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +true+)
388   - # * <tt>:separator</tt> - Sets the separator between the fractional and integer digits (defaults to ".").
389   - # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
390   - # * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+)
391   - # * <tt>:units</tt> - A Hash of unit quantifier names. Or a string containing an i18n scope where to find this hash. It might have the following keys:
392   - # * *integers*: <tt>:unit</tt>, <tt>:ten</tt>, <tt>:hundred</tt>, <tt>:thousand</tt>, <tt>:million</tt>, <tt>:billion</tt>, <tt>:trillion</tt>, <tt>:quadrillion</tt>
393   - # * *fractionals*: <tt>:deci</tt>, <tt>:centi</tt>, <tt>:mili</tt>, <tt>:micro</tt>, <tt>:nano</tt>, <tt>:pico</tt>, <tt>:femto</tt>
394   - # * <tt>:format</tt> - Sets the format of the output string (defaults to "%n %u"). The field types are:
395   - # %u The quantifier (ex.: 'thousand')
396   - # %n The number
397   - # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when the argument is invalid.
398 435 #
  436 + # * <tt>:locale</tt> - Sets the locale to be used for formatting
  437 + # (defaults to current locale).
  438 + # * <tt>:precision</tt> - Sets the precision of the number
  439 + # (defaults to 3).
  440 + # * <tt>:significant</tt> - If +true+, precision will be the #
  441 + # of significant_digits. If +false+, the # of fractional
  442 + # digits (defaults to +true+)
  443 + # * <tt>:separator</tt> - Sets the separator between the
  444 + # fractional and integer digits (defaults to ".").
  445 + # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
  446 + # to "").
  447 + # * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
  448 + # insignificant zeros after the decimal separator (defaults to
  449 + # +true+)
  450 + # * <tt>:units</tt> - A Hash of unit quantifier names. Or a
  451 + # string containing an i18n scope where to find this hash. It
  452 + # might have the following keys:
  453 + # * *integers*: <tt>:unit</tt>, <tt>:ten</tt>,
  454 + # *<tt>:hundred</tt>, <tt>:thousand</tt>, <tt>:million</tt>,
  455 + # *<tt>:billion</tt>, <tt>:trillion</tt>,
  456 + # *<tt>:quadrillion</tt>
  457 + # * *fractionals*: <tt>:deci</tt>, <tt>:centi</tt>,
  458 + # *<tt>:mili</tt>, <tt>:micro</tt>, <tt>:nano</tt>,
  459 + # *<tt>:pico</tt>, <tt>:femto</tt>
  460 + # * <tt>:format</tt> - Sets the format of the output string
  461 + # (defaults to "%n %u"). The field types are:
  462 + # * %u - The quantifier (ex.: 'thousand')
  463 + # * %n - The number
  464 + # * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
  465 + # the argument is invalid.
399 466 #
400 467 # ==== Examples
  468 + #
401 469 # number_to_human(123) # => "123"
402 470 # number_to_human(1234) # => "1.23 Thousand"
403 471 # number_to_human(12345) # => "12.3 Thousand"
@@ -414,8 +482,9 @@ def number_to_human_size(number, options = {})
414 482 # :separator => ',',
415 483 # :significant => false) # => "1,2 Million"
416 484 #
417   - # Unsignificant zeros after the decimal separator are stripped out by default (set
418   - # <tt>:strip_insignificant_zeros</tt> to +false+ to change that):
  485 + # Non-significant zeros after the decimal separator are stripped
  486 + # out by default (set <tt>:strip_insignificant_zeros</tt> to
  487 + # +false+ to change that):
419 488 # number_to_human(12345012345, :significant_digits => 6) # => "12.345 Billion"
420 489 # number_to_human(500000000, :precision => 5) # => "500 Million"
421 490 #

0 comments on commit e8c9aec

Please sign in to comment.
Something went wrong with that request. Please try again.