aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/number_helper
Commit message (Collapse)AuthorAgeFilesLines
* - Extracted `DELIMITED_REGEX` to `delimited_regex` method and made use of ↵Vipul A M2015-08-281-2/+7
| | | | | | | | | | 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-0/+4
|
* Give respond_to? a SymbolAkira Matsuda2015-05-201-1/+1
|
* Freeze static arguments for gsubbrainopia2015-04-024-4/+4
|
* Prefer string patterns for gsubbrainopia2015-04-024-4/+4
| | | | | | | | | | | | | | | | | https://github.com/ruby/ruby/pull/579 - there is a new optimization since ruby 2.2 Previously regexp patterns were faster (since a string was converted to regexp underneath anyway). But now string patterns are faster and better reflect the purpose. Benchmark.ips do |bm| bm.report('regexp') { 'this is ::a random string'.gsub(/::/, '/') } bm.report('string') { 'this is ::a random string'.gsub('::', '/') } bm.compare! end # string: 753724.4 i/s # regexp: 501443.1 i/s - 1.50x slower
* `number_to_percentage` and `precision: 0` work with `NAN` and `INFINITY`.Yves Senn2015-03-061-1/+1
| | | | Closes #19227.
* Doc fix [ci skip]Sushruth Sivaramakrishnan2015-03-051-2/+2
|
* Merge pull request #12067 from jackxxu/keep_precisionRafael Mendonça França2015-02-061-25/+28
| | | | | | | | | 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
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* Do gsub with a regexp instead of a stringPablo Herrero2014-10-292-2/+2
|
* Use zero-padding for number_to_rounded_converterZachary Scott2014-08-221-1/+1
|
* Fixes the digits counter of AS's NumberToRoundedConverterXavier Noria2014-08-201-1/+1
| | | | | | | | | | | Zero has one digit, but Math.log10(0) returns -Infinity. The method needs to special-case zero. The patch adds a regression test that is not clearly related to the underlying issue because digit_count is private and has no coverage. Gray area. This bug was uncovered by 60062cf.
* Fix AS::NumberHelper results with rationalsJuanjo Bazán2014-05-311-5/+1
| | | | | | | | | | :precision was incorrectly being applied to Rationals before: ActiveSupport::NumberHelper.number_to_rounded Rational(10, 3), precision: 2 => "3.3" after: ActiveSupport::NumberHelper.number_to_rounded Rational(10, 3), precision: 2 => "3.33"
* Use block parameter rather than `$1` during `gsub!` so ↵Mark J. Titorenko2014-05-121-1/+3
| | | | | | `ActiveSupport::SafeBuffer` values aren't mangled. Fixes #15064
* fix `number_to_percentage` with `Float::NAN`, `Float::INFINITY`.Yves Senn2014-03-171-2/+1
| | | | | | | Closes #14405. This is a follow-up to 9e997e9039435617b6a844158f5437e97f6bc107 to restore the documented behavior.
* Fix AS::NumberHelper results with large precisionsKenta Murata & Akira Matsuda2013-12-201-7/+37
| | | | | | | | | before: ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50 => "3.14158999999999988261834005243144929409027099609375" after: ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50 => "3.14159000000000000000000000000000000000000000000000"
* Nodoc missing number helper classes in AS [ci skip]Carlos Antonio da Silva2013-12-112-2/+2
| | | | These classes are not meant to be public.
* Remove earlier return in favor of conditionalCarlos Antonio da Silva2013-12-031-6/+9
|
* Change delimiter check order: first check if it is presentCarlos Antonio da Silva2013-12-031-3/+3
| | | | | | | This reads a lot better, and we won't need to try start_with? for blank delimiters. Also rename method name to read better.
* Make both conversion methods work similarlyCarlos Antonio da Silva2013-12-031-1/+2
| | | | | The conversion without area code already changed the passed number in place, so change the other method to do the same.
* Remove useless empty stringCarlos Antonio da Silva2013-12-031-2/+1
|
* No need for #tapCarlos Antonio da Silva2013-12-031-4/+3
|
* Avoid a hash creation since defaults is a new hash alreadyCarlos Antonio da Silva2013-12-031-1/+1
|
* Stop using local variables everywhere, make use of the readerCarlos Antonio da Silva2013-12-036-20/+20
|
* Refactor to avoid earlier returnsCarlos Antonio da Silva2013-12-031-5/+9
|
* Rename variable that holds whether or not the class should validate a float ↵Carlos Antonio da Silva2013-12-035-9/+9
| | | | number
* :sicssors:Rafael Mendonça França2013-12-028-15/+2
|
* Options are not optionalRafael Mendonça França2013-12-021-2/+2
|
* Make execute priave APIRafael Mendonça França2013-12-026-5/+9
|
* Make load of NumberHelper thread safeRafael Mendonça França2013-12-027-19/+0
|
* Merge pull request #10996 from mattdbridges/number-helper-refactorRafael Mendonça França2013-12-021-2/+2
| | | | | | | Refactor and clean up number helpers Conflicts: activesupport/lib/active_support/number_helper.rb
* Extract ActiveSupport::NumberHelper methods to classesMatt Bridges2013-07-018-0/+518
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`