1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

19 commits

Author SHA1 Message Date
Carlos Antonio da Silva
443c31f8fc Nodoc missing number helper classes in AS [ci skip]
These classes are not meant to be public.
2013-12-11 20:01:54 -02:00
Rafael Mendonça França
5c04ca87d8 Make execute priave API 2013-12-02 22:32:21 -02:00
Rafael Mendonça França
d3b93e403b Make load of NumberHelper thread safe 2013-12-02 22:12:36 -02:00
Rafael Mendonça França
fc73ebf332 Merge pull request #10996 from mattdbridges/number-helper-refactor
Refactor and clean up number helpers

Conflicts:
	activesupport/lib/active_support/number_helper.rb
2013-12-02 20:50:03 -02:00
Vipul A M
67c2525d59 Minor Refactoring to NumberHelper#number_to_human
* Use destructive `map` and `sort_by` to save extra object creation.
* Create `INVERTED_DECIMAL_UNITS.invert` constant instead of repeatedly doing `DECIMAL_UNITS.invert`
2013-10-14 23:52:06 +05:30
Mac Martine
ee145c025c Fix typo in number_to_human docs: you -> your 2013-09-24 15:13:23 -07:00
Rafael Mendonça França
816b35e781 Fix examples of number_to_percentage
[ci skip]
2013-07-18 10:33:33 -03:00
Matt Bridges
2da9d67c27 Extract ActiveSupport::NumberHelper methods to classes
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`
2013-07-01 12:31:36 -05:00
Vipul A M
e772daad20 refactor number helper 2013-04-25 00:59:16 +05:30
hoffm
4e3ceedeba Address edge case for number_to_human with units option.
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.
2013-02-22 08:25:51 -05:00
Francesco Rodriguez
f4e180578c update some AS code examples to 1.9 hash syntax [ci skip] 2012-09-12 13:47:49 -05:00
Carlos Antonio da Silva
47b4d13c8d Ensure I18n format values always have precedence over defaults
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.
2012-08-11 00:20:19 -03:00
Carlos Antonio da Silva
a9dccda936 Fallback to :en locale instead of handling a constant with defaults
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.
2012-08-11 00:20:19 -03:00
Carlos Antonio da Silva
36d863ce51 Move constants to the top, remove freeze 2012-06-24 19:30:05 -03:00
Carlos Antonio da Silva
06d50b9d73 Remove some not used variables and improve code a bit 2012-06-24 19:30:05 -03:00
Francesco Rodriguez
1790b234e4 add :nodoc: to AS::NumberHelper private methods [ci skip] 2012-06-05 15:53:20 -05:00
Carlos Antonio da Silva
400c5fefcf Review requires from number helper
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
2012-05-28 23:55:20 -03:00
Jared Beck
371508c240 Fix handling of negative zero in number_to_currency 2012-05-28 04:42:53 -04:00
Andrew Mutz
155cd5e6b5 Moving NumberHelpers from ActionView to ActiveSupport 2012-05-27 18:14:21 -07:00