Skip to content

Commit

Permalink
move element distinction logic to separate module (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein authored May 30, 2024
1 parent fce7562 commit b289075
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
38 changes: 38 additions & 0 deletions src/fundamend/reader/element_distinction.py
Original file line number Diff line number Diff line change
@@ -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"
42 changes: 7 additions & 35 deletions src/fundamend/reader/migreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b289075

Please sign in to comment.