class Numeric

Monkey Patch of the Numeric class

Public Instance Methods

to_human() click to toggle source

Returns a human readable format for a number representing a data size

# File lib/server.rb, line 116
def to_human
  units = %w{B KB MB GB TB}
  e = 0
  e = (Math.log(self)/Math.log(1024)).floor unless self==0
  s = "%.3f" % (to_f / 1024**e)
  s.sub(/\.?0*$/, units[e])
end