Sha256: 8b5d5c74920b5563ea4bd861014d37baee2a74f089e67c1c121ac43d9bdda0a4

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

module OpenVPNStatusWeb
  module Parser
    class ModernStateless
      def self.parse_status_log(text, sep)
        status = Status.new
        status.client_list = []
        status.routing_table = []
        status.global_stats = []

        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"
        end

        status
      end

      private

      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)
        route[3] = DateTime.strptime(route[3], '%a %b %d %k:%M:%S %Y')
        route
      end

      def self.parse_global(global)
        global[1] = global[1].to_i
        global
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
openvpn-status-web-2.0.0 lib/openvpn-status-web/parser/modern_stateless.rb
openvpn-status-web-1.1.0 lib/openvpn-status-web/parser/modern_stateless.rb
openvpn-status-web-1.0.1 lib/openvpn-status-web/parser/modern_stateless.rb
openvpn-status-web-1.0.0 lib/openvpn-status-web/parser/modern_stateless.rb