Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/feedparser/filesizes.rb

Instance Method Summary collapse

Instance Method Details

#to_human_readableObject



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/feedparser/filesizes.rb', line 2

def to_human_readable
  n = self
  if n < 1024
    return "#{n} B"
  elsif n >= 1024 and n < 1024*1024
    return "%.1f KB" % (n.to_f / 1024)
  elsif n >= 1024*1024 and n < 1024*1024*1024
    return "%.1f MB" % (n.to_f / (1024*1024))
  else
    return "%.1f GB" % (n.to_f / (1024*1024*1024))
  end
end