Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/common/hacks.rb

Instance Method Summary collapse

Instance Method Details

#bytes_to_humanObject


102
103
104
105
106
107
# File 'lib/common/hacks.rb', line 102

def bytes_to_human
  units = %w{B KB MB GB TB}
  e = (Math.log(self)/Math.log(1024)).floor
  s = "%.3f" % (to_f / 1024**e)
  s.sub(/\.?0*$/, ' ' + units[e])
end