Adjust str() of HLDS models to deal with int price

This commit is contained in:
Midgard 2020-01-26 15:13:48 +01:00
parent fe593fece6
commit a346220896
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 10 additions and 6 deletions

View file

@ -1,10 +1,10 @@
#!/usr/bin/env python3
# pylint: disable=too-few-public-methods
from typing import List, Mapping, Any
from typing import Iterable, List, Mapping, Any
def _format_tags(tags):
def _format_tags(tags: Iterable[str]) -> str:
return (
" :: {}".format(" ".join(["{" + tag + "}" for tag in tags]))
if tags else
@ -12,6 +12,10 @@ def _format_tags(tags):
)
def _format_price(price: int) -> str:
return "{}.{:02}".format(*divmod(price, 100)) if price else ""
def _format_type_and_choice(type_and_choice):
type_, choice = type_and_choice
return "{} {}".format(type_, choice)
@ -30,7 +34,7 @@ class Option:
self,
" -- {}".format(self.description) if self.description else "",
_format_tags(self.tags),
" {}".format(self.price) if self.price else ""
_format_price(self.price)
)
@ -65,7 +69,7 @@ class Dish:
self,
" -- {}".format(self.description) if self.description else "",
_format_tags(self.tags),
" {}".format(self.price) if self.price else "",
_format_price(self.price),
"\n\t".join(map(_format_type_and_choice, self.choices))
)

View file

@ -6,8 +6,8 @@ testfrituur: Testfrituur
sauce: Saus
ketchup: Ketchup -- Een tomatensaus met veel suiker € 0.8
mayo: Mayonaise -- Eierdooier en olie € 0.8
curry: Currysaus € 0.8
stoofvlees: Stoofvleessaus € 1.4
curry: Currysaus € 0.80
stoofvlees: Stoofvleessaus € 1.41
base veggieburger: Veggieburger € 4.2