Skip to content

Commit

Permalink
adding constant strings to avoid typo errors
Browse files Browse the repository at this point in the history
  • Loading branch information
krady committed Jul 13, 2024
1 parent c5143f3 commit 8b363aa
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/alogamous/log_line_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from __future__ import annotations


class LineType:
HEADER_LINE = "header line"
LOG_LINE = "log line"
UNSTRUCTURED_LINE = "unstructured line"


class LogLineParser:
def __init__(self, header_line: str, expected_fields: list[str], seperator: str):
self.header_line = header_line
Expand All @@ -10,11 +16,11 @@ def __init__(self, header_line: str, expected_fields: list[str], seperator: str)

def parse(self, line):
if line == self.header_line:
return {"type": "header line", "line": line}
return {"type": LineType.HEADER_LINE, "line": line}
if line.count(self.separator) == self.separator_count:
parsed_line = {"type": "log line"}
parsed_line = {"type": LineType.LOG_LINE}
separated_line = line.split(self.separator)
for index in range(len(self.expected_fields)):
parsed_line[self.expected_fields[index]] = separated_line[index]
return parsed_line
return {"type": "unstructured line", "line": line}
return {"type": LineType.UNSTRUCTURED_LINE, "line": line}

0 comments on commit 8b363aa

Please sign in to comment.