Module: Pangea::Util

Defined in:
lib/util/string.rb

Class Method Summary collapse

Class Method Details

.humanize_bytes(bytes) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/util/string.rb', line 4

def self.humanize_bytes(bytes)
  m = bytes.to_i
  units = %w[Bits Bytes MB GB TB PB]
  while (m/1024.0) >= 1 
    m = m/1024.0
    units.shift
  end
  return m.round.to_s + " #{units[0]}"
end