from enum import Enum
from typing import Optional
_link_template_plain = "{{link}}"
_link_template_fancy = """
ILIAS - Link: {{name}}
""".strip() # noqa: E501 line too long
_link_template_internet_shortcut = """
[InternetShortcut]
URL={{link}}
""".strip()
class Links(Enum):
IGNORE = "ignore"
PLAINTEXT = "plaintext"
FANCY = "fancy"
INTERNET_SHORTCUT = "internet-shortcut"
def template(self) -> Optional[str]:
if self == self.FANCY:
return _link_template_fancy
elif self == self.PLAINTEXT:
return _link_template_plain
elif self == self.INTERNET_SHORTCUT:
return _link_template_internet_shortcut
elif self == self.IGNORE:
return None
raise ValueError("Missing switch case")
def extension(self) -> Optional[str]:
if self == self.FANCY:
return ".html"
elif self == self.PLAINTEXT:
return ".txt"
elif self == self.INTERNET_SHORTCUT:
return ".url"
elif self == self.IGNORE:
return None
raise ValueError("Missing switch case")
@staticmethod
def from_string(string: str) -> "Links":
try:
return Links(string)
except ValueError:
raise ValueError("must be one of 'ignore', 'plaintext',"
" 'html', 'internet-shortcut'")