Class: Numeric

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

Overview

Monkey Patch of the Numeric class

Instance Method Summary collapse

Instance Method Details

#to_humanObject

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



116
117
118
119
120
121
122
# 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