Store attributes directly on model instead of in map

This commit is contained in:
Midgard 2020-01-27 00:46:29 +01:00
parent b7cc2048d6
commit 3380d790bc
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 18 additions and 5 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3
# pylint: disable=too-few-public-methods
from typing import Iterable, List, Mapping, Any
from typing import Iterable, List, Mapping, Any, Optional
def _format_tags(tags: Iterable[str]) -> str:
@ -75,10 +75,13 @@ class Dish:
class Location:
def __init__(self, id_, *, name, attributes, dishes):
def __init__(self, id_, *, name, dishes, osm=None, address=None, telephone=None, website=None):
self.id: str = id_
self.name: str = name
self.attributes: Mapping[str, Any] = attributes
self.osm: Optional[str] = osm
self.address: Optional[str] = address
self.telephone: Optional[str] = telephone
self.website: Optional[str] = website
self.dishes: List[Dish] = dishes
@ -92,6 +95,11 @@ class Location:
"{2}"
).format(
self,
"".join("\n\t{} {}".format(k, v) for k, v in self.attributes.items()),
"".join("\n\t{} {}".format(k, v) for k, v in (
("osm", self.osm),
("address", self.address),
("telephone", self.telephone),
("website", self.website),
) if v is not None),
"\n".join(map(str, self.dishes))
)

View file

@ -28,11 +28,16 @@ class HldsSemanticActions:
if not isinstance(choice[1], Choice):
dish.choices[i] = (dish.choices[i][0], choices[choice[1]])
attributes = {att["key"]: att["value"] for att in ast["attributes"]}
return Location(
ast["id"],
name=ast["name"],
attributes={att["key"]: att["value"] for att in ast["attributes"]},
dishes=dishes,
osm=attributes.get("osm"),
address=attributes.get("address"),
telephone=attributes.get("telephone"),
website=attributes.get("website"),
)
def dish_block(self, ast) -> Dish: