2023-05-23 11:59:24 +00:00
|
|
|
from typing import TYPE_CHECKING, List, Iterable
|
2023-03-10 20:28:13 +00:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from .parents import DatabaseObject
|
|
|
|
|
|
|
|
|
|
|
|
class Options:
|
2023-03-10 20:53:25 +00:00
|
|
|
def __init__(self, option_list: List['DatabaseObject'] = None):
|
|
|
|
self._data: List['DatabaseObject'] = option_list or list()
|
2023-03-10 20:28:13 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "\n".join(f"{i:02d}: {database_object.option_string}" for i, database_object in enumerate(self._data))
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
for database_object in self._data:
|
|
|
|
yield database_object
|
2023-05-23 11:59:24 +00:00
|
|
|
|
|
|
|
def append(self, element: 'DatabaseObject'):
|
|
|
|
self._data.append(element)
|
|
|
|
|
|
|
|
def extend(self, iterable: Iterable['DatabaseObject']):
|
|
|
|
for element in iterable:
|
|
|
|
self.append(element)
|
2023-03-10 20:28:13 +00:00
|
|
|
|
|
|
|
def get_next_options(self, index: int) -> 'Options':
|
|
|
|
if index >= len(self._data):
|
|
|
|
raise ValueError("Index out of bounds")
|
|
|
|
|
|
|
|
return self._data[index].options
|
|
|
|
|
2023-03-13 13:47:49 +00:00
|
|
|
def __getitem__(self, item: int) -> 'DatabaseObject':
|
2023-03-10 20:28:13 +00:00
|
|
|
if type(item) != int:
|
|
|
|
raise TypeError("Key needs to be an Integer")
|
2023-03-13 13:47:49 +00:00
|
|
|
if item >= len(self._data):
|
|
|
|
raise ValueError("Index out of bounds")
|
2023-03-10 20:28:13 +00:00
|
|
|
|
2023-03-13 13:47:49 +00:00
|
|
|
return self._data[item]
|
2023-03-28 13:01:47 +00:00
|
|
|
|
|
|
|
def __len__(self) -> int:
|
|
|
|
return len(self._data)
|