aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2006-01-19 05:31:48 +0000
committerMarcel Molina <marcel@vernix.org>2006-01-19 05:31:48 +0000
commit363b79f9428395249d7509ddc88e1080902d6256 (patch)
tree2044bac8fe119c29107a3ce2e1331d8e304d7ce8 /actionpack/lib
parentf0650c51cc1f1b2725765715940d8d2eb5ca8492 (diff)
downloadrails-363b79f9428395249d7509ddc88e1080902d6256.tar.gz
rails-363b79f9428395249d7509ddc88e1080902d6256.tar.bz2
rails-363b79f9428395249d7509ddc88e1080902d6256.zip
Refactor human_size to exclude decimal place if it is zero.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3437 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/helpers/number_helper.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb
index e06eb14f7f..9098dd8c33 100644
--- a/actionpack/lib/action_view/helpers/number_helper.rb
+++ b/actionpack/lib/action_view/helpers/number_helper.rb
@@ -85,15 +85,15 @@ module ActionView
# human_size(1234567) => 1.2 MB
# human_size(1234567890) => 1.1 GB
def number_to_human_size(size)
- begin
- return "%d Bytes" % size if size < 1.kilobytes
- return "%.1f KB" % (size/1.0.kilobytes) if size < 1.megabytes
- return "%.1f MB" % (size/1.0.megabytes) if size < 1.gigabytes
- return "%.1f GB" % (size/1.0.gigabytes) if size < 1.terabytes
- return "%.1f TB" % (size/1.0.terabytes)
- rescue
- # just return nothing
- end
+ case
+ when size < 1.kilobyte: '%d Bytes' % size
+ when size < 1.megabyte: '%.1f KB' % (size / 1.0.kilobyte)
+ when size < 1.gigabyte: '%.1f MB' % (size / 1.0.megabyte)
+ when size < 1.terabyte: '%.1f GB' % (size / 1.0.gigabyte)
+ else '%.1f TB' % (size / 1.0.terabyte)
+ end.sub('.0', '')
+ rescue
+ nil
end
alias_method :human_size, :number_to_human_size # deprecated alias