mirror of
https://github.com/cmur2/openvpn-status-web.git
synced 2025-08-07 22:33:57 +02:00
Convert into gem
This commit is contained in:
16
lib/openvpn-status-web/int_patch.rb
Normal file
16
lib/openvpn-status-web/int_patch.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
class Integer
|
||||
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
|
||||
end
|
Reference in New Issue
Block a user