Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/openvpn-status-web/int_patch.rb

Instance Method Summary collapse

Instance Method Details

#as_bytesObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/openvpn-status-web/int_patch.rb', line 3

def as_bytes
  return "1 Byte" if self == 1
  
  label = ["Bytes", "KiB", "MiB", "GiB", "TiB"]
  i = 0
  num = self.to_f
  while num >= 1024 do
    num = num / 1024
    i += 1
  end
  
  "#{format('%.2f', num)} #{label[i]}"
end