From c53f77f3be76b37e9692db0e3fd0e8c16d954e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 23 Mar 2010 00:26:12 +0100 Subject: Rename unsignificant to insignificant. --- .../lib/action_view/helpers/number_helper.rb | 26 +++++++++++----------- actionpack/lib/action_view/locale/en.yml | 10 ++++----- .../test/template/number_helper_i18n_test.rb | 8 +++---- actionpack/test/template/number_helper_test.rb | 16 ++++++------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index ca2322499c..719b64b940 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -132,7 +132,7 @@ module ActionView # * :significant - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +false+) # * :separator - Sets the separator between the fractional and integer digits (defaults to "."). # * :delimiter - Sets the thousands delimiter (defaults to ""). - # * :strip_unsignificant_zeros - If +true+ removes unsignificant zeros after the decimal separator (defaults to +false+) + # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator (defaults to +false+) # # ==== Examples # number_to_percentage(100) # => 100.000% @@ -221,7 +221,7 @@ module ActionView # * :significant - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +false+) # * :separator - Sets the separator between the fractional and integer digits (defaults to "."). # * :delimiter - Sets the thousands delimiter (defaults to ""). - # * :strip_unsignificant_zeros - If +true+ removes unsignificant zeros after the decimal separator (defaults to +false+) + # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator (defaults to +false+) # # ==== Examples # number_with_precision(111.2345) # => 111.235 @@ -231,7 +231,7 @@ module ActionView # number_with_precision(111.2345, :significant => true) # => 111 # number_with_precision(111.2345, :precision => 1, :significant => true) # => 100 # number_with_precision(13, :precision => 5, :significant => true) # => 13.000 - # number_with_precision(13, :precision => 5, :significant => true, strip_unsignificant_zeros => true) + # number_with_precision(13, :precision => 5, :significant => true, strip_insignificant_zeros => true) # # => 13 # number_with_precision(389.32314, :precision => 4, :significant => true) # => 389.3 # number_with_precision(1111.2345, :precision => 2, :separator => ',', :delimiter => '.') @@ -269,7 +269,7 @@ module ActionView options = options.reverse_merge(defaults) # Allow the user to unset default values: Eg.: :significant => false precision = options.delete :precision significant = options.delete :significant - strip_unsignificant_zeros = options.delete :strip_unsignificant_zeros + strip_insignificant_zeros = options.delete :strip_insignificant_zeros if significant and precision > 0 digits = (Math.log10(number) + 1).floor @@ -280,7 +280,7 @@ module ActionView rounded_number = BigDecimal.new((number * (10 ** precision)).to_s).round.to_f / 10 ** precision end formatted_number = number_with_delimiter("%01.#{precision}f" % rounded_number, options) - if strip_unsignificant_zeros + if strip_insignificant_zeros escaped_separator = Regexp.escape(options[:separator]) formatted_number.sub(/(#{escaped_separator})(\d*[1-9])?0+\z/, '\1\2').sub(/#{escaped_separator}\z/, '').html_safe else @@ -303,7 +303,7 @@ module ActionView # * :significant - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +true+) # * :separator - Sets the separator between the fractional and integer digits (defaults to "."). # * :delimiter - Sets the thousands delimiter (defaults to ""). - # * :strip_unsignificant_zeros - If +true+ removes unsignificant zeros after the decimal separator (defaults to +true+) + # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+) # ==== Examples # number_to_human_size(123) # => 123 Bytes # number_to_human_size(1234) # => 1.21 KB @@ -316,7 +316,7 @@ module ActionView # number_to_human_size(1234567, :precision => 2, :separator => ',') # => 1,2 MB # # Unsignificant zeros after the fractional separator are stripped out by default (set - # :strip_unsignificant_zeros to +false+ to change that): + # :strip_insignificant_zeros to +false+ to change that): # number_to_human_size(1234567890123, :precision => 5) # => "1.1229 TB" # number_to_human_size(524288000, :precision=>5) # => "500 MB" # @@ -349,8 +349,8 @@ module ActionView end options = options.reverse_merge(defaults) - #for backwards compatibility with those that didn't add strip_unsignificant_zeros to their locale files - options[:strip_unsignificant_zeros] = true if not options.key?(:strip_unsignificant_zeros) + #for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files + options[:strip_insignificant_zeros] = true if not options.key?(:strip_insignificant_zeros) storage_units_format = I18n.translate(:'number.human.storage_units.format', :locale => options[:locale], :raise => true) @@ -389,7 +389,7 @@ module ActionView # * :significant - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +true+) # * :separator - Sets the separator between the fractional and integer digits (defaults to "."). # * :delimiter - Sets the thousands delimiter (defaults to ""). - # * :strip_unsignificant_zeros - If +true+ removes unsignificant zeros after the decimal separator (defaults to +true+) + # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+) # * :units - A Hash of unit quantifier names. Or a string containing an i18n scope where to find this hash. It might have the following keys: # * *integers*: :unit, :ten, :hundred, :thousand, :million, :billion, :trillion, :quadrillion # * *fractionals*: :deci, :centi, :mili, :micro, :nano, :pico, :femto @@ -416,7 +416,7 @@ module ActionView # :significant => false) # => "1,2 Million" # # Unsignificant zeros after the decimal separator are stripped out by default (set - # :strip_unsignificant_zeros to +false+ to change that): + # :strip_insignificant_zeros to +false+ to change that): # number_to_human(12345012345, :significant_digits => 6) # => "12.345 Billion" # number_to_human(500000000, :precision=>5) # => "500 Million" # @@ -465,8 +465,8 @@ module ActionView defaults = defaults.merge(human) options = options.reverse_merge(defaults) - #for backwards compatibility with those that didn't add strip_unsignificant_zeros to their locale files - options[:strip_unsignificant_zeros] = true if not options.key?(:strip_unsignificant_zeros) + #for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files + options[:strip_insignificant_zeros] = true if not options.key?(:strip_insignificant_zeros) units = options.delete :units unit_exponents = case units diff --git a/actionpack/lib/action_view/locale/en.yml b/actionpack/lib/action_view/locale/en.yml index cfb4f7c390..a3e2230f6f 100644 --- a/actionpack/lib/action_view/locale/en.yml +++ b/actionpack/lib/action_view/locale/en.yml @@ -13,7 +13,7 @@ # of the number of decimal digits (1234 with precision 2 becomes 1200, 1.23543 becomes 1.2) significant: false # If set, the zeros after the decimal separator will always be stripped (eg.: 1.200 will be 1.2) - strip_unsignificant_zeros: false + strip_insignificant_zeros: false # Used in number_to_currency() currency: @@ -26,7 +26,7 @@ delimiter: "," precision: 2 significant: false - strip_unsignificant_zeros: false + strip_insignificant_zeros: false # Used in number_to_percentage() percentage: @@ -36,7 +36,7 @@ delimiter: "" # precision: # significant: false - # strip_unsignificant_zeros: false + # strip_insignificant_zeros: false # Used in number_to_precision() precision: @@ -46,7 +46,7 @@ delimiter: "" # precision: # significant: false - # strip_unsignificant_zeros: false + # strip_insignificant_zeros: false # Used in number_to_human_size() and number_to_human() human: @@ -56,7 +56,7 @@ delimiter: "" precision: 3 significant: true - strip_unsignificant_zeros: true + strip_insignificant_zeros: true # Used in number_to_human_size() storage_units: # Storage units output formatting. diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index 07a0e2792c..f730a0d7f5 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -6,13 +6,13 @@ class NumberHelperTest < ActionView::TestCase def setup I18n.backend.store_translations 'ts', :number => { - :format => { :precision => 3, :delimiter => ',', :separator => '.', :significant => false, :strip_unsignificant_zeros => false }, + :format => { :precision => 3, :delimiter => ',', :separator => '.', :significant => false, :strip_insignificant_zeros => false }, :currency => { :format => { :unit => '&$', :format => '%u - %n', :precision => 2 } }, :human => { :format => { :precision => 2, :significant => true, - :strip_unsignificant_zeros => true + :strip_insignificant_zeros => true }, :storage_units => { :format => "%n %u", @@ -35,7 +35,7 @@ class NumberHelperTest < ActionView::TestCase } } }, - :percentage => { :format => {:delimiter => '', :precision => 2, :strip_unsignificant_zeros => true} }, + :percentage => { :format => {:delimiter => '', :precision => 2, :strip_insignificant_zeros => true} }, :precision => { :format => {:delimiter => '', :significant => true} } }, :custom_units_for_number_to_human => {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"} @@ -60,7 +60,7 @@ class NumberHelperTest < ActionView::TestCase end def test_number_to_percentage - # to see if strip_unsignificant_zeros is true + # to see if strip_insignificant_zeros is true assert_equal("1%", number_to_percentage(1, :locale => 'ts')) # precision is 2, significant should be inherited assert_equal("1.24%", number_to_percentage(1.2434, :locale => 'ts')) diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index 6adbe9c098..50c57a5588 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -58,7 +58,7 @@ class NumberHelperTest < ActionView::TestCase assert_equal("302.06%", number_to_percentage(302.0574, {:precision => 2})) assert_equal("100.000%", number_to_percentage("100")) assert_equal("1000.000%", number_to_percentage("1000")) - assert_equal("123.4%", number_to_percentage(123.400, :precision => 3, :strip_unsignificant_zeros => true)) + assert_equal("123.4%", number_to_percentage(123.400, :precision => 3, :strip_insignificant_zeros => true)) assert_equal("1.000,000%", number_to_percentage(1000, :delimiter => '.', :separator => ',')) end @@ -124,9 +124,9 @@ class NumberHelperTest < ActionView::TestCase assert_equal "5.392900", number_with_precision(5.3929, :precision => 7, :significant => true ) end - def test_number_with_precision_with_strip_unsignificant_zeros - assert_equal "9775.43", number_with_precision(9775.43, :precision => 4, :strip_unsignificant_zeros => true ) - assert_equal "9775.2", number_with_precision(9775.2, :precision => 6, :significant => true, :strip_unsignificant_zeros => true ) + def test_number_with_precision_with_strip_insignificant_zeros + assert_equal "9775.43", number_with_precision(9775.43, :precision => 4, :strip_insignificant_zeros => true ) + assert_equal "9775.2", number_with_precision(9775.2, :precision => 6, :significant => true, :strip_insignificant_zeros => true ) end def test_number_with_precision_with_significant_true_and_zero_precision @@ -181,7 +181,7 @@ class NumberHelperTest < ActionView::TestCase assert_equal '500 MB', number_to_human_size(524288000, :precision=>3) assert_equal '40 KB', number_to_human_size(41010, :precision => 1) assert_equal '40 KB', number_to_human_size(41100, :precision => 2) - assert_equal '1.0 KB', number_to_human_size(kilobytes(1.0123), :precision => 2, :strip_unsignificant_zeros => false) + assert_equal '1.0 KB', number_to_human_size(kilobytes(1.0123), :precision => 2, :strip_insignificant_zeros => false) assert_equal '1.012 KB', number_to_human_size(kilobytes(1.0123), :precision => 3, :significant => false) assert_equal '1 KB', number_to_human_size(kilobytes(1.0123), :precision => 0, :significant => true) #ignores significant it precision is 0 end @@ -212,7 +212,7 @@ class NumberHelperTest < ActionView::TestCase assert_equal '490 Thousand', number_to_human(489939, :precision => 2) assert_equal '489.9 Thousand', number_to_human(489939, :precision => 4) assert_equal '489 Thousand', number_to_human(489000, :precision => 4) - assert_equal '489.0 Thousand', number_to_human(489000, :precision => 4, :strip_unsignificant_zeros => false) + assert_equal '489.0 Thousand', number_to_human(489000, :precision => 4, :strip_insignificant_zeros => false) assert_equal '1.2346 Million', number_to_human(1234567, :precision => 4, :significant => false) assert_equal '1,2 Million', number_to_human(1234567, :precision => 1, :significant => false, :separator => ',') assert_equal '1 Million', number_to_human(1234567, :precision => 0, :significant => true, :separator => ',') #significant forced to false @@ -289,8 +289,8 @@ class NumberHelperTest < ActionView::TestCase assert !number_to_human_size("").html_safe? assert number_to_human_size("asdf".html_safe).html_safe? - assert number_with_precision(1, :strip_unsignificant_zeros => false).html_safe? - assert number_with_precision(1, :strip_unsignificant_zeros => true).html_safe? + assert number_with_precision(1, :strip_insignificant_zeros => false).html_safe? + assert number_with_precision(1, :strip_insignificant_zeros => true).html_safe? assert !number_with_precision("").html_safe? assert number_with_precision("asdf".html_safe).html_safe? -- cgit v1.2.3