From 7f23c5d52438f12d7af167a399a77025b1d58a9c Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Tue, 4 Nov 2014 12:52:41 +0530 Subject: - Extracted `DELIMITED_REGEX` to `delimited_regex` method and made use of 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 --- activesupport/lib/active_support/number_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport/lib/active_support/number_helper.rb') diff --git a/activesupport/lib/active_support/number_helper.rb b/activesupport/lib/active_support/number_helper.rb index 38a9ce361d..5ab0f0a7ea 100644 --- a/activesupport/lib/active_support/number_helper.rb +++ b/activesupport/lib/active_support/number_helper.rb @@ -135,6 +135,9 @@ module ActiveSupport # to ","). # * :separator - Sets the separator between the # fractional and integer digits (defaults to "."). + # * :delimiter_pattern - Sets a custom regular expression used for + # for deriving, the placement of delimiter. Helpful when using currency + # formats like INR. # # ==== Examples # @@ -147,6 +150,8 @@ module ActiveSupport # number_to_delimited(12345678.05, locale: :fr) # => 12 345 678,05 # number_to_delimited('112a') # => 112a # number_to_delimited(98765432.98, delimiter: ' ', separator: ',') + # number_helper.number_to_delimited("123456.78", + # delimiter_pattern: /(\d+?)(?=(\d\d)+(\d)(?!\d))/) # => 1,23,456.78 # # => 98 765 432,98 def number_to_delimited(number, options = {}) NumberToDelimitedConverter.convert(number, options) -- cgit v1.2.3