Fix ingredient parsing for fractions using '/'
Even though ingredients like '1 1/2 something' already worked fine and got converted to 1.5 something I just came across a recipe using '1/2' as the whole amount without any whole number before that. Apparently I overlooked that case before so I now also fixed that.
This commit is contained in:
@ -28,7 +28,7 @@ def parse_amount(x):
|
|||||||
and (
|
and (
|
||||||
x[end] in string.digits
|
x[end] in string.digits
|
||||||
or (
|
or (
|
||||||
(x[end] == '.' or x[end] == ',')
|
(x[end] == '.' or x[end] == ',' or x[end] == '/')
|
||||||
and end + 1 < len(x)
|
and end + 1 < len(x)
|
||||||
and x[end + 1] in string.digits
|
and x[end + 1] in string.digits
|
||||||
)
|
)
|
||||||
@ -36,6 +36,9 @@ def parse_amount(x):
|
|||||||
):
|
):
|
||||||
end += 1
|
end += 1
|
||||||
if end > 0:
|
if end > 0:
|
||||||
|
if "/" in x[:end]:
|
||||||
|
amount = parse_fraction(x[:end])
|
||||||
|
else:
|
||||||
amount = float(x[:end].replace(',', '.'))
|
amount = float(x[:end].replace(',', '.'))
|
||||||
else:
|
else:
|
||||||
amount = parse_fraction(x[0])
|
amount = parse_fraction(x[0])
|
||||||
|
@ -33,6 +33,7 @@ class TestEditsRecipe(TestBase):
|
|||||||
expectations = {
|
expectations = {
|
||||||
"2¼ l Wasser": (2.25, "l", "Wasser", ""),
|
"2¼ l Wasser": (2.25, "l", "Wasser", ""),
|
||||||
"2¼l Wasser": (2.25, "l", "Wasser", ""),
|
"2¼l Wasser": (2.25, "l", "Wasser", ""),
|
||||||
|
"¼ l Wasser": (0.25, "l", "Wasser", ""),
|
||||||
"3l Wasser": (3, "l", "Wasser", ""),
|
"3l Wasser": (3, "l", "Wasser", ""),
|
||||||
"4 l Wasser": (4, "l", "Wasser", ""),
|
"4 l Wasser": (4, "l", "Wasser", ""),
|
||||||
"½l Wasser": (0.5, "l", "Wasser", ""),
|
"½l Wasser": (0.5, "l", "Wasser", ""),
|
||||||
@ -43,6 +44,10 @@ class TestEditsRecipe(TestBase):
|
|||||||
"1 Zwiebel(n)": (1, "", "Zwiebel(n)", ""),
|
"1 Zwiebel(n)": (1, "", "Zwiebel(n)", ""),
|
||||||
"4 1/2 Zwiebeln": (4.5, "", "Zwiebeln", ""),
|
"4 1/2 Zwiebeln": (4.5, "", "Zwiebeln", ""),
|
||||||
"4 ½ Zwiebeln": (4.5, "", "Zwiebeln", ""),
|
"4 ½ Zwiebeln": (4.5, "", "Zwiebeln", ""),
|
||||||
|
"1/2 EL Mehl": (0.5, "EL", "Mehl", ""),
|
||||||
|
"1/2 Zwiebel": (0.5, "", "Zwiebel", ""),
|
||||||
|
"1/5g Mehl, gesiebt": (0.2, "g", "Mehl", "gesiebt"),
|
||||||
|
"1/2 Zitrone, ausgepresst": (0.5, "", "Zitrone", "ausgepresst"),
|
||||||
"etwas Mehl": (0, "", "etwas Mehl", ""),
|
"etwas Mehl": (0, "", "etwas Mehl", ""),
|
||||||
"Öl zum Anbraten": (0, "", "Öl zum Anbraten", ""),
|
"Öl zum Anbraten": (0, "", "Öl zum Anbraten", ""),
|
||||||
"n. B. Knoblauch, zerdrückt": (0, "", "n. B. Knoblauch", "zerdrückt"),
|
"n. B. Knoblauch, zerdrückt": (0, "", "n. B. Knoblauch", "zerdrückt"),
|
||||||
|
Reference in New Issue
Block a user