Edit category constructor to allow for empty objects.
This commit is contained in:
+12
-15
@@ -8,20 +8,17 @@ from data.score import Score, ScoreTime # pylint: disable=import-error
|
|||||||
class Category:
|
class Category:
|
||||||
"""Stores a category's information and relative scores."""
|
"""Stores a category's information and relative scores."""
|
||||||
|
|
||||||
def __init__(self, name: str, ascending: bool, time_record: bool, score_map: dict) -> None:
|
def __init__(self, name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Default constructor for Category class.
|
Default constructor for Category class. Creates empty category and populates with defaults.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Category's name
|
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._name: str = name
|
||||||
self._ascending: bool = ascending
|
self._ascending: bool = False
|
||||||
self._time_record: bool = time_record
|
self._time_record: bool = False
|
||||||
self._scores_map: dict = score_map
|
self._scores_map: dict = {}
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""
|
"""
|
||||||
@@ -44,16 +41,16 @@ class Category:
|
|||||||
Returns:
|
Returns:
|
||||||
Category: Populated Category object
|
Category: Populated Category object
|
||||||
"""
|
"""
|
||||||
ascending = data["ascending"]
|
category = cls(name)
|
||||||
time_record = data["time_record"]
|
category.ascending = data["ascending"]
|
||||||
score_map = {}
|
category.time_record = data["time_record"]
|
||||||
for user, score in data["scores"].items():
|
for user, score in data["scores"].items():
|
||||||
if time_record:
|
if category.time_record:
|
||||||
score_map[user] = ScoreTime(user, score)
|
category.add_score(ScoreTime(user, score))
|
||||||
else:
|
else:
|
||||||
score_map[user] = Score(user, score)
|
category.add_score(Score(user, score))
|
||||||
|
|
||||||
return cls(name, ascending, time_record, score_map)
|
return category
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ascending(self) -> bool:
|
def ascending(self) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user