feat: add new tags (#16)

This commit is contained in:
Nathaniel Landau
2023-02-04 23:32:55 -05:00
committed by Nathaniel Landau
parent 17985615b3
commit d94d9f2197
10 changed files with 574 additions and 495 deletions

View File

@@ -401,7 +401,7 @@ class InlineMetadata:
"""
return f"InlineMetadata(inline_metadata={self.dict})"
def add(self, key: str, value: str | list[str] = None) -> bool:
def add(self, key: str, value: str = None) -> bool:
"""Add a key and value to the inline metadata.
Args:
@@ -411,15 +411,12 @@ class InlineMetadata:
Returns:
bool: True if the metadata was added
"""
if value is None:
if value is None or value == "" or value == "None":
if key not in self.dict:
self.dict[key] = []
return True
return False
if isinstance(value, list):
value = value[0]
if key not in self.dict:
self.dict[key] = [value]
return True
@@ -564,6 +561,23 @@ class InlineTags:
)
)
def add(self, new_tag: str) -> bool:
"""Add a new inline tag.
Args:
new_tag (str): Tag to add.
Returns:
bool: True if a tag was added.
"""
if new_tag in self.list:
return False
new_list = self.list.copy()
new_list.append(new_tag)
self.list = sorted(new_list)
return True
def contains(self, tag: str, is_regex: bool = False) -> bool:
"""Check if a tag exists in the metadata.