Permalink
Browse files

Deprecation: remove deprecated human_size helper alias. Use number_to…

…_human_size instead.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6407 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent b7107d0 commit 2823a56f14edac7e9012484d375f23c89405d725 @jeremy jeremy committed Mar 13, 2007
View
@@ -1,6 +1,6 @@
*SVN*
-* Deprecation: remove deprecated request, redirect, and dependency methods. Remove deprecated instance variables. Remove uses_component_template_root for toplevel components directory. Privatize deprecated render_partial and render_partial_collection view methods. Remove deprecated link_to_image and link_image_to helper methods. [Jeremy Kemper]
+* Deprecation: remove deprecated request, redirect, and dependency methods. Remove deprecated instance variables. Remove uses_component_template_root for toplevel components directory. Privatize deprecated render_partial and render_partial_collection view methods. Remove deprecated link_to_image and link_image_to helper methods. Remove deprecated human_size helper alias. [Jeremy Kemper]
* Consistent public/protected/private visibility for chained methods. #7813 [Dan Manges]
@@ -50,15 +50,15 @@ def number_to_phone(number, options = {})
# number_to_currency(1234567890.50) => $1,234,567,890.50
# number_to_currency(1234567890.506) => $1,234,567,890.51
# number_to_currency(1234567890.506, :precision => 3) => $1,234,567,890.506
- # number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "")
+ # number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "")
# => £1234567890,50
def number_to_currency(number, options = {})
options = options.stringify_keys
precision = options["precision"] || 2
unit = options["unit"] || "$"
separator = precision > 0 ? options["separator"] || "." : ""
delimiter = options["delimiter"] || ","
-
+
begin
parts = number_with_precision(number, precision).split('.')
unit + number_with_delimiter(parts[0], delimiter) + separator + parts[1].to_s
@@ -79,7 +79,7 @@ def number_to_percentage(number, options = {})
options = options.stringify_keys
precision = options["precision"] || 3
separator = options["separator"] || "."
-
+
begin
number = number_with_precision(number, precision)
parts = number.split('.')
@@ -110,7 +110,7 @@ def number_with_delimiter(number, delimiter=",", separator=".")
number
end
end
-
+
# Formats a +number+ with the specified level of +precision+. The default
# level of precision is 3.
#
@@ -121,12 +121,12 @@ def number_with_precision(number, precision=3)
rescue
number
end
-
+
# Formats the bytes in +size+ into a more understandable representation.
- # Useful for reporting file sizes to users. This method returns nil if
- # +size+ cannot be converted into a number. You can change the default
+ # Useful for reporting file sizes to users. This method returns nil if
+ # +size+ cannot be converted into a number. You can change the default
# precision of 1 in +precision+.
- #
+ #
# number_to_human_size(123) => 123 Bytes
# number_to_human_size(1234) => 1.2 KB
# number_to_human_size(12345) => 12.1 KB
@@ -136,7 +136,7 @@ def number_with_precision(number, precision=3)
# number_to_human_size(1234567, 2) => 1.18 MB
def number_to_human_size(size, precision=1)
size = Kernel.Float(size)
- case
+ case
when size == 1 : "1 Byte"
when size < 1.kilobyte: "%d Bytes" % size
when size < 1.megabyte: "%.#{precision}f KB" % (size / 1.0.kilobyte)
@@ -147,9 +147,6 @@ def number_to_human_size(size, precision=1)
rescue
nil
end
-
- alias_method :human_size, :number_to_human_size # deprecated alias
- deprecate :human_size => :number_to_human_size
end
end
end
@@ -86,10 +86,4 @@ def test_number_to_human_size
assert_nil number_to_human_size('x')
assert_nil number_to_human_size(nil)
end
-
- def test_human_size_alias_is_deprecated
- assert_deprecated 'human_size' do
- assert_equal '0 Bytes', human_size(0)
- end
- end
end

0 comments on commit 2823a56

Please sign in to comment.