Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/server.rb
Overview
Monkey Patch of the Numeric class
Instance Method Summary collapse
-
#to_human ⇒ Object
Returns a human readable format for a number representing a data size.
Instance Method Details
#to_human ⇒ Object
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 |