Skip to content

Commit

Permalink
Add xref to Structure
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Oct 10, 2022
1 parent 08eff9d commit a18b651
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions gedcom7/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def loads(string: str) -> List[GedcomStructure]:
structure = GedcomStructure(
tag=ext.get(data["tag"]) or data["tag"],
pointer=data["pointer"],
xref=data["xref"],
text=data["linestr"],
)
# handle extension tags
Expand Down
12 changes: 12 additions & 0 deletions gedcom7/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Classes and data types."""

import re
from typing import Optional, List

from . import grammar


class GedcomStructure:
"""Gedcom structure class."""
Expand All @@ -11,13 +14,15 @@ def __init__(
tag: str,
pointer: str,
text: str,
xref: str,
children: Optional[List["GedcomStructure"]] = None,
):
"""Initialize self."""
self.tag = tag
self.pointer = pointer
self.text = text
self.children = children or []
self.xref = xref
self.parent: Optional["GedcomStructure"] = None

def __repr__(self):
Expand All @@ -30,3 +35,10 @@ def __repr__(self):
f"tag={self.tag}, pointer={self.pointer}, text={self.text}, "
f"children={repr_children}"
)

def as_list_enum(self) -> List[str]:
"""Return as list enum data type."""
match = re.fullmatch(grammar.list_enum, self.text)
if not match:
raise ValueError(f"Cannot interpret {self.text} as type list enum")
return [el.strip() for el in self.text.split(",")]

0 comments on commit a18b651

Please sign in to comment.