Redo table docstrings.
This commit is contained in:
+70
-9
@@ -9,16 +9,39 @@ class Table:
|
|||||||
"""Stores a table's information a list of categories."""
|
"""Stores a table's information a list of categories."""
|
||||||
|
|
||||||
def __init__(self, name: str, message_id: int, category_map: dict) -> None:
|
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._name: str = name
|
||||||
self._message_id: int = message_id
|
self._message_id: int = message_id
|
||||||
self._categories_map: dict = category_map
|
self._categories_map: dict = category_map
|
||||||
|
|
||||||
def __str__(self) -> str:
|
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)
|
return json.dumps(self.to_dict(), indent=4)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, table_name: str, data: dict):
|
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"]
|
message_id = data["message_id"]
|
||||||
category_map = {}
|
category_map = {}
|
||||||
for cat_name, cat in data["categories"].items():
|
for cat_name, cat in data["categories"].items():
|
||||||
@@ -29,37 +52,75 @@ class Table:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def categories(self) -> "list[Category]":
|
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()
|
return self._categories_map.values()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def message_id(self) -> int:
|
def message_id(self) -> int:
|
||||||
"""Getter for message id."""
|
"""
|
||||||
|
Getter for message id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: message id
|
||||||
|
"""
|
||||||
return self._message_id
|
return self._message_id
|
||||||
|
|
||||||
@message_id.setter
|
@message_id.setter
|
||||||
def message_id(self, m_id: int) -> None:
|
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
|
self._message_id = m_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Getter for name."""
|
"""
|
||||||
|
Getter for name.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: name
|
||||||
|
"""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
def add_category(self, category: Category) -> None:
|
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:
|
if category.name not in self._categories_map:
|
||||||
self._categories_map[category.name] = category
|
self._categories_map[category.name] = category
|
||||||
|
|
||||||
def get_category(self, category_name: str) -> 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:
|
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.
|
Does not include table name. It should be the key of above data structure.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: Table class in dictionary format
|
||||||
"""
|
"""
|
||||||
data = {}
|
data = {}
|
||||||
data["message_id"] = self.message_id
|
data["message_id"] = self.message_id
|
||||||
|
|||||||
Reference in New Issue
Block a user