Skip to content

Commit a18b651

Browse files
committed
Add xref to Structure
1 parent 08eff9d commit a18b651

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

gedcom7/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def loads(string: str) -> List[GedcomStructure]:
2323
structure = GedcomStructure(
2424
tag=ext.get(data["tag"]) or data["tag"],
2525
pointer=data["pointer"],
26+
xref=data["xref"],
2627
text=data["linestr"],
2728
)
2829
# handle extension tags

gedcom7/types.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""Classes and data types."""
22

3+
import re
34
from typing import Optional, List
45

6+
from . import grammar
7+
58

69
class GedcomStructure:
710
"""Gedcom structure class."""
@@ -11,13 +14,15 @@ def __init__(
1114
tag: str,
1215
pointer: str,
1316
text: str,
17+
xref: str,
1418
children: Optional[List["GedcomStructure"]] = None,
1519
):
1620
"""Initialize self."""
1721
self.tag = tag
1822
self.pointer = pointer
1923
self.text = text
2024
self.children = children or []
25+
self.xref = xref
2126
self.parent: Optional["GedcomStructure"] = None
2227

2328
def __repr__(self):
@@ -30,3 +35,10 @@ def __repr__(self):
3035
f"tag={self.tag}, pointer={self.pointer}, text={self.text}, "
3136
f"children={repr_children}"
3237
)
38+
39+
def as_list_enum(self) -> List[str]:
40+
"""Return as list enum data type."""
41+
match = re.fullmatch(grammar.list_enum, self.text)
42+
if not match:
43+
raise ValueError(f"Cannot interpret {self.text} as type list enum")
44+
return [el.strip() for el in self.text.split(",")]

0 commit comments

Comments
 (0)