ingredient aliases
This commit is contained in:
parent
7cf5b7ef29
commit
4cc0656e88
1 changed files with 9 additions and 2 deletions
11
recipes.py
11
recipes.py
|
@ -31,7 +31,7 @@ class Units:
|
||||||
class Ingredient:
|
class Ingredient:
|
||||||
def load(self, dct: Dict[str, Any]) -> List[str]:
|
def load(self, dct: Dict[str, Any]) -> List[str]:
|
||||||
issues = []
|
issues = []
|
||||||
issues += assert_dict(dct, ["name"], ["wdid", "pricedb"])
|
issues += assert_dict(dct, ["name"], ["wdid", "pricedb", "aliases"])
|
||||||
|
|
||||||
assert_type(dct, "name", str)
|
assert_type(dct, "name", str)
|
||||||
self.name = dct["name"]
|
self.name = dct["name"]
|
||||||
|
@ -47,6 +47,13 @@ class Ingredient:
|
||||||
self.pricedb = PriceDBs()
|
self.pricedb = PriceDBs()
|
||||||
issues += self.pricedb.load(dct["pricedb"])
|
issues += self.pricedb.load(dct["pricedb"])
|
||||||
|
|
||||||
|
self.aliases = []
|
||||||
|
if "aliases" in dct:
|
||||||
|
assert_list(dct["aliases"])
|
||||||
|
for elem in dct["aliases"]:
|
||||||
|
assert_type(elem, "", str)
|
||||||
|
self.aliases.append(elem)
|
||||||
|
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,7 +72,7 @@ class Ingredients:
|
||||||
|
|
||||||
def get(self, name: str) -> Optional[Ingredient]:
|
def get(self, name: str) -> Optional[Ingredient]:
|
||||||
for ing in self.ingredients:
|
for ing in self.ingredients:
|
||||||
if ing.name == name:
|
if ing.name == name or name in ing.aliases:
|
||||||
return ing
|
return ing
|
||||||
raise RuntimeError(f"ingredient {name} not found")
|
raise RuntimeError(f"ingredient {name} not found")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue