1
0
mirror of https://github.com/cmur2/openvpn-status-web.git synced 2025-07-01 22:30:23 +02:00
Files
openvpn-status-web/lib/openvpn-status-web/int_patch.rb
2020-03-07 01:30:57 +01:00

18 lines
270 B
Ruby

# frozen_string_literal: true
class Integer
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
end