Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #238 #239

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions crabpy/gateway/adressenregister.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,16 @@ class Straat(GatewayObject):
A street object is always located in one and exactly one :class:`Gemeente`.
"""

def __init__(self, id_, gateway, gemeente=AUTO, status=AUTO, naam=AUTO, uri=AUTO):
def __init__(
self,
id_,
gateway,
gemeente=AUTO,
status=AUTO,
naam=AUTO,
uri=AUTO,
homoniem=AUTO,
):
super().__init__(gateway)
self.id = id_
if naam is not AUTO:
Expand All @@ -680,6 +689,12 @@ def __init__(self, id_, gateway, gemeente=AUTO, status=AUTO, naam=AUTO, uri=AUTO
if not callable(naam):
raise ValueError("naam must be a callable")
self.naam = naam
if homoniem is not AUTO:
if isinstance(homoniem, str):
homoniem = CallableString(homoniem)
if not callable(homoniem):
raise ValueError("homoniem must be a callable")
self.homoniem = homoniem
if status is not AUTO:
self.status = status
if gemeente is not AUTO:
Expand All @@ -694,6 +709,9 @@ def from_list_response(cls, straat, gateway):
status=straat["straatnaamStatus"],
naam=straat["straatnaam"]["geografischeNaam"]["spelling"],
uri=straat["identificator"]["id"],
homoniem=straat["homoniemToevoeging"]["geografischeNaam"]["spelling"]
if straat.get("homoniemToevoeging")
else AUTO,
gateway=gateway,
)

Expand All @@ -717,6 +735,26 @@ def naam(self, taal="nl"):

return self._source_json["straatnamen"][0]["spelling"]

def homoniem(self, taal="nl"):
homoniem = next(
(
homoniemtoevoeging["spelling"]
for homoniemtoevoeging in self._source_json.get(
"homoniemToevoegingen", []
)
if homoniemtoevoeging["taal"] == taal
),
None,
)
if homoniem:
return homoniem

return (
self._source_json["homoniemToevoegingen"][0]["spelling"]
if self._source_json.get("homoniemToevoegingen")
else None
)

@LazyProperty
def uri(self):
return self._source_json["identificator"]["id"]
Expand Down Expand Up @@ -828,6 +866,11 @@ def straat(self):
naam=self._source_json["straatnaam"]["straatnaam"]["geografischeNaam"][
"spelling"
],
homoniem=self._source_json["homoniemToevoeging"]["geografischeNaam"][
"spelling"
]
if self._source_json.get("homoniemToevoeging")
else AUTO,
gateway=self.gateway,
)

Expand Down Expand Up @@ -920,7 +963,9 @@ class Gebouw(GatewayObject):
A building.
"""

def __init__(self, id_, gateway, status=AUTO, percelen=AUTO, geojson=AUTO, uri=AUTO):
def __init__(
self, id_, gateway, status=AUTO, percelen=AUTO, geojson=AUTO, uri=AUTO
):
super().__init__(gateway=gateway)
self.id = id_
if status is not AUTO:
Expand Down