class Integer

Public Instance Methods

as_bytes() click to toggle source
# File lib/openvpn-status-web/int_patch.rb, line 4
def as_bytes
  return '1 Byte' if self == 1

  label = %w[Bytes KiB MiB GiB TiB]
  i = 0
  num = to_f
  while num >= 1024
    num /= 1024
    i += 1
  end

  "#{format('%.2f', num)} #{label[i]}"
end