diff --git a/data/table.py b/data/table.py index ed2e61b..d3697f4 100644 --- a/data/table.py +++ b/data/table.py @@ -9,16 +9,39 @@ class Table: """Stores a table's information a list of categories.""" def __init__(self, name: str, message_id: int, category_map: dict) -> None: + """ + Default constructor for Table class. + + Args: + name (str): Table's name + message_id (int): message id of message table is displayed on in discord + category_map (dict): map of Categories + """ self._name: str = name self._message_id: int = message_id self._categories_map: dict = category_map def __str__(self) -> str: + """ + Returns Table class as a string for printing. + + Returns: + str: Table class as a string + """ return json.dumps(self.to_dict(), indent=4) @classmethod def from_dict(cls, table_name: str, data: dict): - """Fills out table from passed dictionary.""" + """ + Creates a Table class from the passed data. + + Args: + table_name (str): Table name + data (dict): Rest of Table data in dictionary format + + Returns: + Table: Populated Table class + """ message_id = data["message_id"] category_map = {} for cat_name, cat in data["categories"].items(): @@ -29,37 +52,75 @@ class Table: @property def categories(self) -> "list[Category]": - """Returns list of categories.""" + """ + Getter for Categories list. + + Returns: + list[Category]: List of Categories in this Table + """ return self._categories_map.values() @property def message_id(self) -> int: - """Getter for message id.""" + """ + Getter for message id + + Returns: + int: message id + """ return self._message_id @message_id.setter def message_id(self, m_id: int) -> None: - """Setter for message id.""" + """ + Setter for message id. + + Args: + m_id (int): message id + """ self._message_id = m_id @property def name(self) -> str: - """Getter for name.""" + """ + Getter for name. + + Returns: + str: name + """ return self._name def add_category(self, category: Category) -> None: - """Adds a category to dictionary of categories. Shouldn't already exist.""" + """ + Adds a Category to categories map. Shouldn't exist already. + + Args: + category (Category): Category to add + """ if category.name not in self._categories_map: self._categories_map[category.name] = category def get_category(self, category_name: str) -> Category: - """Getter for specific category.""" - return self._categories_map[category_name] + """ + Getter for specific category. Returns None if not found. + + Args: + category_name (str): name of category to return + + Returns: + Category: Category corresponding to name. None if not found. + """ + if category_name in self._categories_map: + return self._categories_map[category_name] + return None def to_dict(self) -> dict: """ - Saves table as a python dictionary. + Saves Table as a python dictionary. Does not include table name. It should be the key of above data structure. + + Returns: + dict: Table class in dictionary format """ data = {} data["message_id"] = self.message_id