From 7ace0f471d7d8d602696286ff0f222d5c939ae7c Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Fri, 17 May 2024 12:56:03 +0100 Subject: [PATCH] New logic --- main.rb | 3 ++- utils/date_for_humans.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 utils/date_for_humans.rb diff --git a/main.rb b/main.rb index 6a6a412..4fe5b14 100644 --- a/main.rb +++ b/main.rb @@ -2,6 +2,7 @@ require 'date' require_relative 'utils/http_codes' +require_relative 'utils/date_for_humans' logfile = File.open("teambuilder.pt.log") data = logfile.read @@ -19,6 +20,7 @@ def get_line_date(line) pattern = /\[(.*?)\]/ 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("]", "")) end @@ -85,7 +87,6 @@ lines.each do |line| code = get_line_code(line) ua = get_line_ua(line) - #if code.to_i >= 400 && code.to_i < 500 if is_client_err?(code.to_i) if client_errors[ip] client_errors[ip] += 1 diff --git a/utils/date_for_humans.rb b/utils/date_for_humans.rb new file mode 100644 index 0000000..269913d --- /dev/null +++ b/utils/date_for_humans.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# array with list of months in portuguese +# @return [Array] list of months in portuguese +def months + %w[janeiro fevereiro março abril maio junho julho agosto setembro outubro novembro dezembro] +end + +# Returns the month in portuguese +def month_for_humans(month) + months[month - 1] +end