Generalize shortened file.schema attribute

This commit is contained in:
Thomas Krijnen
2024-01-04 15:05:40 +01:00
committed by GitHub
parent 00576ef574
commit 77a497cdf7
+13 -1
View File
@@ -358,7 +358,19 @@ class file(object):
if attr[0:6] == "create":
return functools.partial(self.create_entity, attr[6:])
elif attr == "schema":
return {"IFC4X3_ADD1": "IFC4X3"}.get(self.wrapped_data.schema, self.wrapped_data.schema)
prefixes = ("IFC", "X", "_ADD", "_TC")
reg = "".join(f"(?P<{s}>{s}\d+)?" for s in prefixes)
match = re.match(reg, self.wrapped_data.schema)
version_tuple = tuple(
map(
lambda pp: int(pp[1][len(pp[0]):]) if pp[1] else None,
((p, match.group(p)) for p in prefixes),
)
)
return "".join(
"".join(map(str, t)) if t[1] else ""
for t in zip(prefixes, version_tuple[0:2])
)
elif attr == "schema_identifier":
return self.wrapped_data.schema
elif attr == "schema_version":