Python

Python examples that may help you create clean arch

Understanding Enum, Factory, and interfaces


class Journal(Enum):
    journal_a = auto()
    journal_b = auto()
    journal_c = auto()

    @staticmethod
    def from_str(journal_name: str) -> Journal:
        if journal_name not in Journal.__members__:
            raise ValueError(f"{journal_name} has not been implemented")
        return Journal.__members__[journal_name]


class Parser:
    @staticmethod
    def parse_html(document: str) -> BeautifulSoup:
        ...
        return BeautifulSoup(xml, "html.parser")

    @abstractmethod
    def extract_figures(self, raw_http_document: str) -> List[Figure]:
        raise NotImplementedError

    @abstractmethod
    def extract_document(self, raw_http_document: str) -> Document:
        raise NotImplementedError

    @staticmethod
    def from_journal(journal: Journal) -> Parser:
        match journal:
            case Journal.journal_a:
                return JournalAParser(
                )
            case _:
                raise NotImplementedError