2020-01-25 01:33:23 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-01-26 01:45:20 +01:00
|
|
|
# pylint: disable=too-few-public-methods
|
2020-01-25 01:33:23 +01:00
|
|
|
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
2020-01-26 01:29:19 +01:00
|
|
|
def _format_tags(tags):
|
|
|
|
return (
|
|
|
|
" :: {}".format(" ".join(["{" + tag + "}" for tag in tags]))
|
|
|
|
if tags else
|
|
|
|
""
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-01-26 02:09:53 +01:00
|
|
|
def _format_type_and_choice(type_and_choice):
|
|
|
|
type_, choice = type_and_choice
|
|
|
|
return "{} {}".format(type_, choice)
|
|
|
|
|
|
|
|
|
2020-01-25 01:33:23 +01:00
|
|
|
class Option:
|
2020-01-26 01:29:19 +01:00
|
|
|
def __init__(self, id_, *, name, description, price, tags):
|
2020-01-25 01:33:23 +01:00
|
|
|
self.id = id_
|
|
|
|
self.name = name
|
|
|
|
self.description = description
|
2020-01-26 01:29:19 +01:00
|
|
|
self.price = price
|
|
|
|
self.tags = tags
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "{0.id}: {0.name}{1}{2}{3}".format(
|
|
|
|
self,
|
|
|
|
" -- {}".format(self.description) if self.description else "",
|
|
|
|
_format_tags(self.tags),
|
|
|
|
" {}".format(self.price) if self.price else ""
|
|
|
|
)
|
2020-01-25 01:33:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Choice:
|
2020-01-26 01:29:19 +01:00
|
|
|
def __init__(self, id_, *, name, description, options):
|
2020-01-25 01:33:23 +01:00
|
|
|
self.id = id_
|
|
|
|
self.name = name
|
|
|
|
self.description = description
|
|
|
|
|
|
|
|
self.options: List[Option] = options
|
|
|
|
|
2020-01-26 01:29:19 +01:00
|
|
|
def __str__(self):
|
|
|
|
return "{0.id}: {0.name}{1}\n\t\t{2}".format(
|
|
|
|
self,
|
|
|
|
" -- {}".format(self.description) if self.description else "",
|
|
|
|
"\n\t\t".join(map(str, self.options))
|
|
|
|
)
|
2020-01-25 01:33:23 +01:00
|
|
|
|
2020-01-26 01:29:19 +01:00
|
|
|
|
|
|
|
class Dish:
|
|
|
|
def __init__(self, id_, *, name, description, price, tags, choices):
|
2020-01-25 01:33:23 +01:00
|
|
|
self.id = id_
|
|
|
|
self.name = name
|
2020-01-26 01:29:19 +01:00
|
|
|
self.description = description
|
|
|
|
self.price = price
|
|
|
|
self.tags = tags
|
2020-01-25 01:33:23 +01:00
|
|
|
|
2020-01-26 02:09:53 +01:00
|
|
|
self.choices: List[(str, Choice)] = choices
|
2020-01-26 01:29:19 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
2020-01-26 02:09:53 +01:00
|
|
|
return "base {0.id}: {0.name}{1}{2}{3}\n\t{4}".format(
|
2020-01-26 01:29:19 +01:00
|
|
|
self,
|
|
|
|
" -- {}".format(self.description) if self.description else "",
|
|
|
|
_format_tags(self.tags),
|
|
|
|
" {}".format(self.price) if self.price else "",
|
2020-01-26 02:09:53 +01:00
|
|
|
"\n\t".join(map(_format_type_and_choice, self.choices))
|
2020-01-26 01:29:19 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Location:
|
|
|
|
def __init__(self, id_, *, name, attributes, dishes):
|
|
|
|
self.id = id_
|
|
|
|
self.name = name
|
|
|
|
self.attributes = attributes
|
|
|
|
|
|
|
|
self.dishes: List[Dish] = dishes
|
|
|
|
|
|
|
|
def __str__(self):
|
2020-01-26 01:45:20 +01:00
|
|
|
return (
|
|
|
|
"============================\n"
|
|
|
|
"{0.id}: {0.name}\n"
|
|
|
|
"============================\n"
|
|
|
|
"\n"
|
|
|
|
"{1}"
|
|
|
|
).format(
|
2020-01-26 01:29:19 +01:00
|
|
|
self,
|
2020-01-26 01:45:20 +01:00
|
|
|
"\n".join(map(str, self.dishes))
|
2020-01-26 01:29:19 +01:00
|
|
|
)
|