| 1 | """Base interface for selection of components.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from abc import ABC, abstractmethod |
| 6 | from typing import TYPE_CHECKING, Sequence |
| 7 | |
| 8 | if TYPE_CHECKING: |
| 9 | from icalendar.cal import Component |
| 10 | |
| 11 | from recurring_ical_events.series import Series |
| 12 | |
| 13 | |
| 14 | class SelectComponents(ABC): |
| 15 | """Abstract class to select components from a calendar.""" |
| 16 | |
| 17 | @staticmethod |
| 18 | def component_name(): |
| 19 | """The name of the component if there is only one.""" |
| 20 | raise NotImplementedError("This should be implemented in subclasses.") |
| 21 | |
| 22 | @abstractmethod |
| 23 | def collect_series_from( |
| 24 | self, source: Component, suppress_errors: tuple[Exception] |
| 25 | ) -> Sequence[Series]: |
| 26 | """Collect all components from the source grouped together into a series. |
| 27 | |
| 28 | suppress_errors - a list of errors that should be suppressed. |
| 29 | A Series of events with such an error is removed from all results. |
| 30 | """ |
| 31 | |
| 32 | |
| 33 | __all__ = ["SelectComponents"] |