From e56a553c9536225296a98f82d4625ee2b94a2b2f Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 3 Dec 2013 19:49:19 -0200 Subject: Stop using local variables everywhere, make use of the reader --- .../lib/active_support/number_helper/number_converter.rb | 6 +++--- .../number_helper/number_to_currency_converter.rb | 4 ++-- .../number_helper/number_to_human_converter.rb | 6 +++--- .../number_helper/number_to_human_size_converter.rb | 12 ++++++------ .../number_helper/number_to_phone_converter.rb | 2 +- .../number_helper/number_to_rounded_converter.rb | 10 +++++----- 6 files changed, 20 insertions(+), 20 deletions(-) (limited to 'activesupport/lib/active_support/number_helper') diff --git a/activesupport/lib/active_support/number_helper/number_converter.rb b/activesupport/lib/active_support/number_helper/number_converter.rb index 471c686997..9d976f1831 100644 --- a/activesupport/lib/active_support/number_helper/number_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_converter.rb @@ -124,10 +124,10 @@ module ActiveSupport end def execute - if !@number + if !number nil elsif validate_float? && !valid_float? - @number + number else convert end @@ -173,7 +173,7 @@ module ActiveSupport end def valid_float? #:nodoc: - Float(@number) + Float(number) rescue ArgumentError, TypeError false end 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 28f33164a5..11ba0605e0 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 @@ -4,8 +4,8 @@ module ActiveSupport self.namespace = :currency def convert - number = @number.to_s.strip - format = options[:format] + number = self.number.to_s.strip + format = options[:format] if is_negative?(number) format = options[:negative_format] 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 1ced75ed8a..9a3dc526ae 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 @@ -9,7 +9,7 @@ module ActiveSupport self.validate_float = true def convert # :nodoc: - @number = Float(@number) + @number = Float(number) # for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files unless options.key?(:strip_insignificant_zeros) @@ -18,11 +18,11 @@ module ActiveSupport units = opts[:units] exponent = calculate_exponent(units) - @number = @number / (10 ** exponent) + @number = number / (10 ** exponent) unit = determine_unit(units, exponent) - rounded_number = NumberToRoundedConverter.convert(@number, options) + 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 37590c27ef..d1335f6910 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 @@ -7,7 +7,7 @@ module ActiveSupport self.validate_float = true def convert - @number = Float(@number) + @number = Float(number) # for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files unless options.key?(:strip_insignificant_zeros) @@ -15,9 +15,9 @@ module ActiveSupport end if smaller_than_base? - number_to_format = @number.to_i.to_s + number_to_format = number.to_i.to_s else - human_size = @number / (base ** exponent) + human_size = number / (base ** exponent) number_to_format = NumberToRoundedConverter.convert(human_size, options) end conversion_format.gsub(/%n/, number_to_format).gsub(/%u/, unit) @@ -30,7 +30,7 @@ module ActiveSupport end def unit - translate_number_value_with_default(storage_unit_key, :locale => options[:locale], :count => @number.to_i, :raise => true) + translate_number_value_with_default(storage_unit_key, :locale => options[:locale], :count => number.to_i, :raise => true) end def storage_unit_key @@ -40,13 +40,13 @@ module ActiveSupport def exponent max = STORAGE_UNITS.size - 1 - exp = (Math.log(@number) / Math.log(base)).to_i + exp = (Math.log(number) / Math.log(base)).to_i exp = max if exp > max # avoid overflow for the highest unit exp end def smaller_than_base? - @number.to_i < base + number.to_i < base end def base diff --git a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb index 9828bec053..ac51ceabc1 100644 --- a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb @@ -4,7 +4,7 @@ module ActiveSupport def convert str = '' str << country_code(opts[:country_code]) - str << convert_to_phone_number(@number.to_s.strip) + str << convert_to_phone_number(number.to_s.strip) str << phone_ext(opts[:extension]) 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 708fb57185..c736469355 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 @@ -5,7 +5,7 @@ module ActiveSupport self.validate_float = true def convert - @number = Float(@number) + @number = Float(number) precision = options.delete :precision significant = options.delete :significant @@ -15,7 +15,7 @@ module ActiveSupport precision -= digits precision = 0 if precision < 0 # don't let it be negative else - rounded_number = BigDecimal.new(@number.to_s).round(precision).to_f + 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 @@ -26,8 +26,8 @@ module ActiveSupport private def digits_and_rounded_number(precision) - return [1,0] if @number.zero? - digits = digit_count(@number) + return [1,0] if number.zero? + digits = digit_count(number) multiplier = 10 ** (digits - precision) rounded_number = calculate_rounded_number(multiplier) digits = digit_count(rounded_number) # After rounding, the number of digits may have changed @@ -35,7 +35,7 @@ module ActiveSupport end def calculate_rounded_number(multiplier) - (BigDecimal.new(@number.to_s) / BigDecimal.new(multiplier.to_f.to_s)).round.to_f * multiplier + (BigDecimal.new(number.to_s) / BigDecimal.new(multiplier.to_f.to_s)).round.to_f * multiplier end def digit_count(number) -- cgit v1.2.3