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: