1
0
mirror of https://github.com/cmur2/openvpn-status-web.git synced 2025-06-29 10:30:23 +02:00

gem: add rubocop and fix style

This commit is contained in:
cn
2020-03-02 01:57:58 +01:00
parent d959e7fe62
commit 140c60c753
11 changed files with 175 additions and 67 deletions

View File

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

View File

@ -10,29 +10,27 @@ module OpenVPNStatusWeb
text.lines.each do |line|
parts = line.strip.split(sep)
status.client_list << parse_client(parts[1..5]) if parts[0] == "CLIENT_LIST"
status.routing_table << parse_route(parts[1..4]) if parts[0] == "ROUTING_TABLE"
status.global_stats << parse_global(parts[1..2]) if parts[0] == "GLOBAL_STATS"
status.client_list << parse_client(parts[1..5]) if parts[0] == 'CLIENT_LIST'
status.routing_table << parse_route(parts[1..4]) if parts[0] == 'ROUTING_TABLE'
status.global_stats << parse_global(parts[1..2]) if parts[0] == 'GLOBAL_STATS'
end
status
end
private
def self.parse_client(client)
private_class_method def self.parse_client(client)
client[2] = client[2].to_i
client[3] = client[3].to_i
client[4] = DateTime.strptime(client[4], '%a %b %d %k:%M:%S %Y')
client
end
def self.parse_route(route)
private_class_method def self.parse_route(route)
route[3] = DateTime.strptime(route[3], '%a %b %d %k:%M:%S %Y')
route
end
def self.parse_global(global)
private_class_method def self.parse_global(global)
global[1] = global[1].to_i
global
end

View File

@ -13,7 +13,7 @@ module OpenVPNStatusWeb
(current_section = :rt; next) if line == "ROUTING TABLE\n"
(current_section = :gs; next) if line == "GLOBAL STATS\n"
(current_section = :end; next) if line == "END\n"
case current_section
when :cl
client_list << line.strip.split(',')

View File

@ -1,4 +1,4 @@
module OpenVPNStatusWeb
VERSION = "2.0.0"
VERSION = '2.0.0'.freeze
end