aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/number_helper.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add missing `+` around a some literals.bogdanvlviv2016-10-271-2/+2
| | | | | | Mainly around `nil` [ci skip]
* `number_to_phone` formats number with regexpPan GaoYong2016-04-021-1/+8
| | | | | | | | | | | | By default, this method formats US number. This commit extends its functionality to format number for other countries with a custom regular expression. number_to_phone(18812345678, pattern: /(\d{3})(\d{4})(\d{4})/) # => 188-1234-5678 The output phone number is divided into three groups, so the regexp should also match three groups of numbers.
* Show correct return types for examples [ci skip]Gert Goet2016-02-201-59/+59
|
* Merge pull request #22759 from akshay-vishnoi/human-size-helperEileen M. Uchitelle2015-12-271-0/+2
|\ | | | | Add support for Petabyte and Exabyte in number to human size
| * Add support for Petabyte and Exabyte in number to human sizeAkshay Vishnoi2015-12-221-0/+2
| |
* | Add caveat to number_to_currency docs [ci skip]Derek Prior2015-12-231-0/+8
|/ | | | | | | | | | | | | | I've worked on a few applications that have gone through the internationalization process and had issues because they were using `number_to_currency`. The minute a user is allowed to change their locale, they can change the price displayed on a page from 10 US dollars to 10 Mexican Pesos, which is far from the same amount of money. Unlike other helpers that rely on i18n, `number_to_currency` does not produce equivalent results when the locale is changed. As I've explained this to a few groups of developers now, I thought it might make for a good caveat in the docs.
* Fixed `ActiveSupport::NumberHelper` Outputs [ci skip]amitkumarsuroliya2015-10-111-2/+2
|
* Correcting output of `number_to_percentage` example in `number_helper` [ci skip]amitkumarsuroliya2015-09-221-1/+1
| | | Here is correct output of `number_to_percentage(100, format: "%n %”)`
* Tiny documentation improvements [ci skip]Robin Dupret2015-08-281-5/+6
|
* - Extracted `DELIMITED_REGEX` to `delimited_regex` method and made use of ↵Vipul A M2015-08-281-0/+5
| | | | | | | | | | user passed `options[:delimited_regex]` if available. Changed `DELIMITED_REGEX` to `DEFAULT)DELIMITED_REGEX` to signify what it means. - Added tests for number to delimited and number to currency in both actionview and activesupport. Changes Changes
* Deprecate the :prefix option of `number_to_human_size`Jean Boussier2015-08-101-2/+0
|
* Fix spelling [ci skip]Yu Haidong2015-03-041-8/+8
|
* Merge pull request #12067 from jackxxu/keep_precisionRafael Mendonça França2015-02-061-2/+4
|\ | | | | | | | | | | | | | | | | Enable number_to_percentage to keep the number's precision by allowing :precision option value to be nil Conflicts: activesupport/CHANGELOG.md activesupport/lib/active_support/number_helper.rb activesupport/test/number_helper_test.rb
| * Enable number_to_percentage to keep the number's precision by allowing ↵Jack Xu2013-08-281-16/+22
| | | | | | | | | | | | :precision to be nil number_helper.number_to_percentage(1000, precision: nil) # => "1000%"
* | Fix doc markup for `NumberHelper` [ci skip]Ryunosuke SATO2014-10-291-5/+5
| | | | | | | | | | The character "*" is unnecessary in option candidates. This incorrect markup was injected in e8c9aeca .
* | [ci skip] Add Docs for strip_insignificant_zeros option in number helpersAkshay Vishnoi2014-06-101-8/+7
| |
* | [ci skip] Correct output and use valid options of number helpersAkshay Vishnoi2014-06-101-2/+2
| |
* | Nodoc missing number helper classes in AS [ci skip]Carlos Antonio da Silva2013-12-111-2/+0
| | | | | | | | These classes are not meant to be public.
* | Make execute priave APIRafael Mendonça França2013-12-021-7/+7
| |
* | Make load of NumberHelper thread safeRafael Mendonça França2013-12-021-7/+11
| |
* | Merge pull request #10996 from mattdbridges/number-helper-refactorRafael Mendonça França2013-12-021-306/+15
|\ \ | | | | | | | | | | | | | | | | | | Refactor and clean up number helpers Conflicts: activesupport/lib/active_support/number_helper.rb
| * | Extract ActiveSupport::NumberHelper methods to classesMatt Bridges2013-07-011-308/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to the overall complexity of each method individually as well as the global shared private module methods, this pulls each helper into it's own converter class inheriting from a generic `NumberBuilder` class. * The `NumberBuilder` class contains the private methods needed for each helper method an eliminates the need for special definition of specialized private module methods. * The `ActiveSupport::NumberHelper::DEFAULTS` constant has been moved into the `NumberBuilder` class because the `NumberBuilder` is the only class which needs access to it. * For each of the builders, the `#convert` method is broken down to smaller parts and extracted into private methods for clarity of purpose. * Most of the mutation that once was necessary has now been eliminated. * Several of the mathematical operations for percentage, delimited, and rounded have been moved into private methods to ease readability and clarity. * Internationalization is still a bit crufty, and definitely could be improved, but it is functional and a bit easier to follow. The following helpers were extracted into their respective classes. * `#number_to_percentage` -> `NumberToPercentageConverter` * `#number_to_delimited` -> `NumberToDelimitedConverter` * `#number_to_phone` -> `NumberToPhoneConverter` * `#number_to_currency` -> `NumberToCurrencyConverter` * `#number_to_rounded` -> `NumberToRoundedConverter` * `#number_to_human_size` -> `NumberToHumanSizeConverter` * `#number_to_human` -> `NumberToHumanConverter`
* | | Minor Refactoring to `NumberHelper#number_to_human`Vipul A M2013-10-141-4/+2
| | | | | | | | | | | | | | | * Use destructive `map` and `sort_by` to save extra object creation. * Create `INVERTED_DECIMAL_UNITS.invert` constant instead of repeatedly doing `DECIMAL_UNITS.invert`
* | | Fix typo in number_to_human docs: you -> yourMac Martine2013-09-241-1/+1
| |/ |/|
* | Fix examples of number_to_percentageRafael Mendonça França2013-07-181-8/+8
|/ | | | [ci skip]
* refactor number helperVipul A M2013-04-251-2/+3
|
* Address edge case for number_to_human with units option.hoffm2013-02-221-1/+1
| | | | | | ActiveSupport::NumberHelper#number_to_human now returns the number unaltered when the units hash does not contain the needed key, e.g. when the number provided is less than the largest key provided.
* update some AS code examples to 1.9 hash syntax [ci skip]Francesco Rodriguez2012-09-121-10/+10
|
* Ensure I18n format values always have precedence over defaultsCarlos Antonio da Silva2012-08-111-42/+40
| | | | | | | | | | | | | | | | | | | Always merge I18n format values, namespaced or not, over the default ones, to ensure I18n format defaults will have precedence over our namespaced values. Precedence should happen like this: default :format default :namespace :format i18n :format i18n :namespace :format Because we cannot allow our namespaced default to override a I18n :format config - ie precision in I18n :format should always have higher precedence than our default precision for a particular :namespace. Also simplify default format options logic.
* Fallback to :en locale instead of handling a constant with defaultsCarlos Antonio da Silva2012-08-111-19/+130
| | | | | | | | Action Pack already comes with a default locale fine for :en, that is always loaded. We can just fallback to this locale for defaults, if values for the current locale cannot be found. Closes #4420, #2802, #2890.
* Move constants to the top, remove freezeCarlos Antonio da Silva2012-06-241-5/+5
|
* Remove some not used variables and improve code a bitCarlos Antonio da Silva2012-06-241-12/+7
|
* add :nodoc: to AS::NumberHelper private methods [ci skip]Francesco Rodriguez2012-06-051-99/+100
|
* Review requires from number helperCarlos Antonio da Silva2012-05-281-5/+4
| | | | | | | | Some of these requires are now only necessary in ActiveSupport::NumberHelper. Add hash/keys require due to symbolize_keys usage in number helpers. Also remove some whitespaces. Closes #6414
* Fix handling of negative zero in number_to_currencyJared Beck2012-05-281-1/+1
|
* Moving NumberHelpers from ActionView to ActiveSupportAndrew Mutz2012-05-271-0/+532