From a1f574e2daf5e5bf650feac5d59a74328e78ce32 Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Sun, 19 May 2024 03:44:18 +0100 Subject: [PATCH] refactor: fix rubocop offenses --- .idea/ApacheLogStats.iml | 13 +++++++++++++ main.rb | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.idea/ApacheLogStats.iml b/.idea/ApacheLogStats.iml index 0fcd036..bd3fe53 100644 --- a/.idea/ApacheLogStats.iml +++ b/.idea/ApacheLogStats.iml @@ -12,6 +12,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/main.rb b/main.rb index 4fe5b14..016234c 100644 --- a/main.rb +++ b/main.rb @@ -4,7 +4,7 @@ require 'date' require_relative 'utils/http_codes' require_relative 'utils/date_for_humans' -logfile = File.open("teambuilder.pt.log") +logfile = File.open('teambuilder.pt.log') data = logfile.read lines = data.split("\n") @@ -21,7 +21,7 @@ def get_line_date(line) match = line.match(pattern)[0] if line.match(pattern) # [12/Apr/2023:13:56:41 +0100] -> 12/Apr/2023:13:56:41 +0100 - Date.parse(match.gsub("[", "").gsub("]", "")) + Date.parse(match.gsub('[', '').gsub(']', '')) end # Gets the HTTP status code of the given log line @@ -104,13 +104,13 @@ lines.each do |line| end top_user_agents = user_agents.sort_by { |ua, count| -count }.first(5) -puts "Top 5 User-Agents contacting the site:" +puts 'Top 5 User-Agents contacting the site:' top_user_agents.each do |ua, count| puts "#{ua}: #{count} visits" end top_client_errors = client_errors.sort_by { |ip, count| -count }.first(5) -puts "Top 5 IPs with most client errors (400-499):" +puts 'Top 5 IPs with most client errors (400-499):' top_client_errors.each do |ip, count| puts "#{ip}: #{count} errors" end \ No newline at end of file