Class: Numeric

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

Overview

Hack of the Numeric class

Instance Method Summary collapse

Instance Method Details

#bytes_to_humanString

Returns A human readable string of the value.

Returns:

  • (String)

    A human readable string of the value



4
5
6
7
8
9
10
# File 'lib/cms_scanner/numeric.rb', line 4

def bytes_to_human
  units = %w[B KB MB GB TB]
  e     = abs.zero? ? abs : (Math.log(abs) / Math.log(1024)).floor
  s     = format('%.3f', (abs.to_f / 1024**e))

  s.sub(/\.?0*$/, ' ' + units[e])
end