From 5e0285028e7bd2360e048b3ff1f461940689edf6 Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Sun, 19 May 2024 17:06:53 +0100 Subject: [PATCH] refactor: update ide ruby version, fix rubocop offenses --- .idea/ApacheLogStats.iml | 30 +++++++++++++-------------- .idea/dictionaries/miguelnogueira.xml | 3 +++ main.rb | 12 +++++------ 3 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 .idea/dictionaries/miguelnogueira.xml diff --git a/.idea/ApacheLogStats.iml b/.idea/ApacheLogStats.iml index bd3fe53..a39aa12 100644 --- a/.idea/ApacheLogStats.iml +++ b/.idea/ApacheLogStats.iml @@ -10,21 +10,21 @@ - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/miguelnogueira.xml b/.idea/dictionaries/miguelnogueira.xml new file mode 100644 index 0000000..3cfb57d --- /dev/null +++ b/.idea/dictionaries/miguelnogueira.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/main.rb b/main.rb index 016234c..9c59f35 100644 --- a/main.rb +++ b/main.rb @@ -42,9 +42,7 @@ end def times_appeared_single(ips, ip_to_check) counter = 0 ips.each do |ip| - if ip == ip_to_check - counter += 1 - end + counter += 1 if ip == ip_to_check end counter end @@ -69,7 +67,7 @@ client_errors = {} user_agents = {} all_ips = [] -lines.each do | line | +lines.each do |line| all_ips << get_line_ip(line) end @@ -103,14 +101,14 @@ lines.each do |line| end -top_user_agents = user_agents.sort_by { |ua, count| -count }.first(5) +top_user_agents = user_agents.sort_by { |_ua, count| -count }.first(5) 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) +top_client_errors = client_errors.sort_by { |_ip, count| -count }.first(5) 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 +end