music-kraken-core/src/music_kraken/objects/option.py

29 lines
863 B
Python
Raw Normal View History

2023-03-10 20:28:13 +00:00
from typing import TYPE_CHECKING, List
if TYPE_CHECKING:
from .parents import DatabaseObject
class Options:
def __init__(self, option_list: List[DatabaseObject] = None):
self._data: List[DatabaseObject] = option_list or list()
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
def get_next_options(self, index: int) -> 'Options':
if index >= len(self._data):
raise ValueError("Index out of bounds")
return self._data[index].options
def __getitem__(self, item: int) -> 'Options':
if type(item) != int:
raise TypeError("Key needs to be an Integer")
return self.get_next_options(item)