From b289075535854f60b97dc8173e9ea52c44b9c2f6 Mon Sep 17 00:00:00 2001 From: konstantin Date: Thu, 30 May 2024 18:23:53 +0200 Subject: [PATCH] move element distinction logic to separate module (#7) --- src/fundamend/reader/element_distinction.py | 38 +++++++++++++++++++ src/fundamend/reader/migreader.py | 42 ++++----------------- 2 files changed, 45 insertions(+), 35 deletions(-) create mode 100644 src/fundamend/reader/element_distinction.py diff --git a/src/fundamend/reader/element_distinction.py b/src/fundamend/reader/element_distinction.py new file mode 100644 index 0000000..a47f114 --- /dev/null +++ b/src/fundamend/reader/element_distinction.py @@ -0,0 +1,38 @@ +"""shared logic between MIG and AHB reader to distinguish elements from the XML""" + +import xml.etree.ElementTree as ET + + +def _is_segment_group(element: ET.Element) -> bool: + """ + returns True if the given element is a segment group + """ + return element.tag.startswith("G_SG") + + +def _is_segment(element: ET.Element) -> bool: + """ + returns True if the given element is a segment + """ + return element.tag.startswith("S_") + + +def _is_data_element_group(element: ET.Element) -> bool: + """ + returns True if the given element is a data element group + """ + return element.tag.startswith("C_") + + +def _is_data_element(element: ET.Element) -> bool: + """ + returns True if the given element is a data element + """ + return element.tag.startswith("D_") + + +def _is_code(element: ET.Element) -> bool: + """ + returns True if the given element is a code + """ + return element.tag == "Code" diff --git a/src/fundamend/reader/migreader.py b/src/fundamend/reader/migreader.py index ae7a3b6..5b06749 100644 --- a/src/fundamend/reader/migreader.py +++ b/src/fundamend/reader/migreader.py @@ -15,41 +15,13 @@ Segment, SegmentGroup, ) - - -def _is_segment_group(element: ET.Element) -> bool: - """ - returns True if the given element is a segment group - """ - return element.tag.startswith("G_SG") - - -def _is_segment(element: ET.Element) -> bool: - """ - returns True if the given element is a segment - """ - return element.tag.startswith("S_") - - -def _is_data_element_group(element: ET.Element) -> bool: - """ - returns True if the given element is a data element group - """ - return element.tag.startswith("C_") - - -def _is_data_element(element: ET.Element) -> bool: - """ - returns True if the given element is a data element - """ - return element.tag.startswith("D_") - - -def _is_code(element: ET.Element) -> bool: - """ - returns True if the given element is a code - """ - return element.tag == "Code" +from fundamend.reader.element_distinction import ( + _is_code, + _is_data_element, + _is_data_element_group, + _is_segment, + _is_segment_group, +) def _to_code(element: ET.Element) -> Code: