This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from Qwant/block-delivery
add block `delivery`
- Loading branch information
Showing
8 changed files
with
106 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from enum import Enum | ||
from typing import Literal | ||
|
||
from .base import BaseBlock | ||
|
||
|
||
class DeliveryState(Enum): | ||
YES = "yes" | ||
UNKNOWN = "unknown" | ||
|
||
@classmethod | ||
def from_bool(cls, is_yes: bool): | ||
return cls.YES if is_yes else cls.UNKNOWN | ||
|
||
|
||
class DeliveryBlock(BaseBlock): | ||
type: Literal["delivery"] = "delivery" | ||
click_and_collect: DeliveryState | ||
delivery: DeliveryState | ||
takeaway: DeliveryState | ||
|
||
@classmethod | ||
def from_es(cls, place, lang): | ||
states = { | ||
"click_and_collect": DeliveryState.from_bool(place.has_click_and_collect()), | ||
"delivery": DeliveryState.from_bool(place.has_delivery()), | ||
"takeaway": DeliveryState.from_bool(place.has_takeaway()), | ||
} | ||
|
||
if all(state == DeliveryState.UNKNOWN for state in states.values()): | ||
return None | ||
|
||
return cls(**states) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from idunn.blocks.delivery import DeliveryBlock | ||
from idunn.places import POI | ||
|
||
|
||
def test_delivery_block(): | ||
delivery_block = DeliveryBlock.from_es( | ||
POI({"properties": {"delivery": "yes", "takeaway": "yes"}}), lang="en" | ||
) | ||
|
||
assert delivery_block == DeliveryBlock( | ||
click_and_collect="unknown", | ||
delivery="yes", | ||
takeaway="yes", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters