Skip to content
Snippets Groups Projects

ENH: add convenience functions

Merged Henrik tom Wörden requested to merge f-version-convenience into dev
Files
3
@@ -505,6 +505,10 @@ class Entity:
return self
def get_versionid(self):
"""Returns the concatenation of ID and version"""
return str(self.id)+"@"+str(self.version.id)
def get_importance(self, property): # @ReservedAssignment
"""Get the importance of a given property regarding this entity."""
@@ -2125,6 +2129,14 @@ class Property(Entity):
else:
return is_reference(self.datatype)
def value_matches_versionid(self):
"""Returns True if the value matches the pattern <id>@<version>"""
return value_matches_versionid(self.value)
def get_id_from_versionid_value(self):
"""Returns the ID part of the versionid with the pattern <id>@<version>"""
return get_id_from_versionid(self.value)
class Message(object):
@@ -5670,3 +5682,18 @@ def _filter_entity_list_by_identity(listobject: list[Entity],
if pid_none and name_match:
matches.append(candidate)
return matches
def value_matches_versionid(value: Union[int, str]):
"""Returns True if the value matches the pattern <id>@<version>"""
if isinstance(value, int):
return False
if not isinstance(value, str):
raise ValueError(f"A reference value needs to be int or str. It was {type(value)}. "
"Did you call value_matches_versionid on a non reference value?")
return "@" in value
def get_id_from_versionid(versionid: str):
"""Returns the ID part of the versionid with the pattern <id>@<version>"""
return versionid.split("@")[0]
Loading