Redo category docstrings.

This commit is contained in:
alwayscompiling
2022-08-01 22:17:52 -04:00
parent 2ee2d3405e
commit e43a0a8977
+75 -11
View File
@@ -9,18 +9,41 @@ class Category:
"""Stores a category's information and relative scores."""
def __init__(self, name: str, ascending: bool, time_record: bool, score_map: dict) -> None:
"""
Default constructor for Category class.
Args:
name (str): Category's name
ascending (bool): If category is ascending or decending
time_record (bool): If category is time record or not
score_map (dict): map of Scores
"""
self._name: str = name
self._ascending: bool = ascending
self._time_record: bool = time_record
self._scores_map: dict = score_map
def __str__(self) -> str:
"""Creates a string from the class."""
"""
Returns Category class as a string for printing.
Returns:
str: Category class as a string
"""
return json.dumps(self.to_dict(), indent=4)
@classmethod
def from_dict(cls, name: str, data: dict):
"""Fills out category from passed dictionary"""
"""
Creates a Category class from the passed data.
Args:
name (str): Category name
data (dict): Rest of Category data in dictionary format
Returns:
Category: Populated Category class
"""
ascending = data["ascending"]
time_record = data["time_record"]
score_map = {}
@@ -34,26 +57,51 @@ class Category:
@property
def ascending(self) -> bool:
"""Getter for ascending bool."""
"""
Getter for is ascending
Returns:
bool: is ascending
"""
return self._ascending
@property
def name(self) -> str:
"""Getter for name."""
"""
Getter for name.
Returns:
str: name
"""
return self._name
@property
def time_record(self) -> bool:
"""Getter for time record bool."""
"""
Getter for is time record.
Returns:
bool: is time record
"""
return self._time_record
@property
def scores(self) -> "list[Score]":
"""Getter for scores list."""
"""
Getter for Scores list.
Returns:
list[Score]: List of Scores in this Category
"""
return self._scores_map.values()
def add_score(self, score: Score) -> None:
"""Adds a score to dictionary storage. Then sorts dictionary by score value."""
"""
Adds score to dictionary storage map. Sorts dictionary by score value.
Args:
score (Score): Score to be added
"""
if score.user in self._scores_map:
self._scores_map[score.user].value = score.value
else:
@@ -64,20 +112,36 @@ class Category:
)
def get_user_score(self, user: str) -> Score:
"""Gets a user's score. None if doesn't exist."""
"""
Gets a user's score. Returns None if user is not found.
Args:
user (str): Name of score to find
Returns:
Score: User's Score or None
"""
if user in self.scores:
return self._scores_map[user]
return None
def remove_score(self, score: Score) -> None:
"""Removes a score from dictionary storage."""
score = self._scores_map.pop(score.user)
def remove_score(self, score: str) -> None:
"""
Removes a user's score from dictionary storage.
Args:
score (str): user whose score to remove
"""
score = self._scores_map.pop(score)
del score
def to_dict(self) -> dict:
"""
Saves category data as a python dictionary.
Does not include category name. It should be the key of above data structure.
Returns:
dict: Category class in dictionary format
"""
data = {}
data["ascending"] = self.ascending