File: filesizes.rb

package info (click to toggle)
ruby-feedparser 0.11.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 228 kB
  • sloc: ruby: 1,871; sh: 24; makefile: 5
file content (14 lines) | stat: -rw-r--r-- 344 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Integer
  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
end