diff options
Diffstat (limited to 'activesupport/lib/active_support/number_helper')
6 files changed, 9 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/number_helper/number_converter.rb b/activesupport/lib/active_support/number_helper/number_converter.rb index 39255d14a3..0afa08db84 100644 --- a/activesupport/lib/active_support/number_helper/number_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_converter.rb @@ -115,6 +115,9 @@ module ActiveSupport } } + def self.convert(number, options) + new(number, options).execute + end def initialize(number, opts = {}) @number = number diff --git a/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb b/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb index 113e557415..90a3cede3a 100644 --- a/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb @@ -13,7 +13,7 @@ module ActiveSupport number = absolute_value(number) end - rounded_number = NumberToRoundedConverter.new(number, options).execute + rounded_number = NumberToRoundedConverter.convert(number, options) format.gsub('%n', rounded_number).gsub('%u', options[:unit]) end diff --git a/activesupport/lib/active_support/number_helper/number_to_human_converter.rb b/activesupport/lib/active_support/number_helper/number_to_human_converter.rb index 3cdf6ff9f8..0c1a7250e3 100644 --- a/activesupport/lib/active_support/number_helper/number_to_human_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_human_converter.rb @@ -23,7 +23,7 @@ module ActiveSupport unit = determine_unit(units, exponent) - rounded_number = NumberToRoundedConverter.new(@number, options).execute + rounded_number = NumberToRoundedConverter.convert(@number, options) format.gsub(/%n/, rounded_number).gsub(/%u/, unit).strip end diff --git a/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb b/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb index 6a0f6e70b7..467ad030b5 100644 --- a/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb @@ -19,7 +19,7 @@ module ActiveSupport number_to_format = @number.to_i.to_s else human_size = @number / (base ** exponent) - number_to_format = NumberToRoundedConverter.new(human_size, options).execute + number_to_format = NumberToRoundedConverter.convert(human_size, options) end conversion_format.gsub(/%n/, number_to_format).gsub(/%u/, unit) end diff --git a/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb b/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb index b7926cf151..c654bfaa3a 100644 --- a/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb @@ -5,7 +5,7 @@ module ActiveSupport self.namespace = :percentage def convert - rounded_number = NumberToRoundedConverter.new(number, options).execute + rounded_number = NumberToRoundedConverter.convert(number, options) options[:format].gsub('%n', rounded_number) end diff --git a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb index 355c810dc9..820e1534e2 100644 --- a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb @@ -19,7 +19,8 @@ module ActiveSupport rounded_number = BigDecimal.new(@number.to_s).round(precision).to_f rounded_number = rounded_number.abs if rounded_number.zero? # prevent showing negative zeros end - delimited_number = NumberToDelimitedConverter.new("%01.#{precision}f" % rounded_number, options).execute + + delimited_number = NumberToDelimitedConverter.convert("%01.#{precision}f" % rounded_number, options) format_number(delimited_number) end |