Skip to content

jmenu.classes

Contains dataclasses jmenu uses to manage data. This file can be imported and exposes the following classes:

* MenuItem
* Restaurant
* Marker

The following collections are use-case specific to the University of Oulu:

* MARKERS
* RESTAURANTS
* SKIPPED_ITEMS

Marker

Bases: NamedTuple

Dataclass for allergen information markings

Attributes:

Name Type Description
letters str

allergen markings

explanation dict

extended information about the marker, in lang_code: explanation pairs.

Methods:

Name Description
get_explanation

str): returns the explanation string for this Marker. Defaults to english.

Source code in src/jmenu/classes.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class Marker(NamedTuple):
    """Dataclass for allergen information markings

    Attributes:
        letters (str):
            allergen markings
        explanation (dict):
            extended information about the marker, in lang_code: explanation pairs.


    Methods:
        get_explanation(lang: str): returns the explanation string for this Marker. Defaults to english.
    """

    letters: str
    explanation: Mapping

    def get_explanation(self, lang_code: str = "en"):
        "Returns the explanation in the language specified by lang_code. Defaults to english."
        exp = self.explanation.get(lang_code)
        return exp if exp is not None else f"No explanation available for '{lang_code}'"

get_explanation(lang_code='en')

Returns the explanation in the language specified by lang_code. Defaults to english.

Source code in src/jmenu/classes.py
81
82
83
84
def get_explanation(self, lang_code: str = "en"):
    "Returns the explanation in the language specified by lang_code. Defaults to english."
    exp = self.explanation.get(lang_code)
    return exp if exp is not None else f"No explanation available for '{lang_code}'"

MenuItem

Bases: NamedTuple

Dataclass for single menu items and their properties

Attributes:

Name Type Description
name str

name of the dish

diets [str]

list of allergen markers

Methods:

Name Description
diets_to_string

returns the list of diets as a joined string.

Source code in src/jmenu/classes.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class MenuItem(NamedTuple):
    """Dataclass for single menu items and their properties

    Attributes:
        name (str):
            name of the dish
        diets ([str]):
            list of allergen markers

    Methods:
        diets_to_string: returns the list of diets as a joined string.
    """

    name: str
    diets: Iterable[str]

    def diets_to_string(self) -> str:
        """Returns the diets associated with this MenuItem as spaced string."""
        return " ".join(self.diets)

diets_to_string()

Returns the diets associated with this MenuItem as spaced string.

Source code in src/jmenu/classes.py
36
37
38
def diets_to_string(self) -> str:
    """Returns the diets associated with this MenuItem as spaced string."""
    return " ".join(self.diets)

Restaurant

Bases: NamedTuple

Dataclass for relevant restaurant information

Attributes:

Name Type Description
name str

name of the restaurant

client_id int

internal jamix identifier used for restaurant providers

kitchen_id int

internal jamix identifier used to assign menu content

menu_type int

internal jamix identifier used to classify menus based on content

relevant_menus [str]

menu names used for filtering out desserts etc.

Source code in src/jmenu/classes.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Restaurant(NamedTuple):
    """Dataclass for relevant restaurant information

    Attributes:
        name (str):
            name of the restaurant
        client_id (int):
            internal jamix identifier used for restaurant providers
        kitchen_id (int):
            internal jamix identifier used to assign menu content
        menu_type (int):
            internal jamix identifier used to classify menus based on content
        relevant_menus ([str]):
            menu names used for filtering out desserts etc.
    """

    name: str
    client_id: int
    kitchen_id: int
    menu_type: int
    relevant_menus: Iterable[str]