mirror of
https://github.com/shouptech/synthale.git
synced 2026-02-03 07:29:42 +00:00
Add fermentable table
This commit is contained in:
parent
a8cb7a3d69
commit
89174a2838
2 changed files with 61 additions and 1 deletions
|
|
@ -12,7 +12,11 @@ from synthale import markdown, convert
|
|||
class MarkdownRecipe:
|
||||
"""A recipe in markdown form."""
|
||||
|
||||
def __init__(self, recipe, vol_unit='gallons', hop_unit='ounces'):
|
||||
def __init__(self,
|
||||
recipe,
|
||||
vol_unit='gallons',
|
||||
hop_unit='ounces',
|
||||
fermentable_unit='pounds'):
|
||||
"""Create a MarkdownRecipe object.
|
||||
|
||||
`recipe` is a recipe object from the pybeerxml package.
|
||||
|
|
@ -23,10 +27,15 @@ class MarkdownRecipe:
|
|||
`hop_unit` specifies the unit for hop amounts. Can be one of
|
||||
'ounces', 'pounds', 'grams', or 'kilograms'. If specified unit is not
|
||||
matched, default is 'ounces'.
|
||||
|
||||
`fermentable_unit` specifies the unit for fermentable amounts. Can be
|
||||
one of 'ounces', 'pounds', 'grams', or 'kilograms'. If specified unit
|
||||
is not matched, default is 'pounds'.
|
||||
"""
|
||||
self.recipe = recipe
|
||||
self.vol_unit = vol_unit
|
||||
self.hop_unit = hop_unit
|
||||
self.fermentable_unit = fermentable_unit
|
||||
|
||||
@property
|
||||
def filename(self):
|
||||
|
|
@ -54,6 +63,8 @@ class MarkdownRecipe:
|
|||
'',
|
||||
self.details,
|
||||
'',
|
||||
self.fermentables,
|
||||
'',
|
||||
self.hops,
|
||||
'',
|
||||
))
|
||||
|
|
@ -109,6 +120,33 @@ class MarkdownRecipe:
|
|||
self.recipe.abv)
|
||||
))
|
||||
|
||||
@property
|
||||
def fermentables(self):
|
||||
"""Return markdown to represent the recipe's fermentables."""
|
||||
headers = ('Name', 'Type', 'Color', 'Amount')
|
||||
rows = []
|
||||
for fermentable in self.recipe.fermentables:
|
||||
if self.fermentable_unit == 'ounces':
|
||||
amt = convert.ounces(fermentable.amount, '.1f')
|
||||
elif self.fermentable_unit == 'grams':
|
||||
amt = convert.grams(fermentable.amount, '.1f')
|
||||
elif self.fermentable_unit == 'kilograms':
|
||||
amt = convert.kilograms(fermentable.amount, '.2f')
|
||||
else:
|
||||
amt = convert.pounds(fermentable.amount, '.2f')
|
||||
rows.append((
|
||||
fermentable.name,
|
||||
fermentable.type,
|
||||
'{:.1f} °L'.format(fermentable.color),
|
||||
amt
|
||||
))
|
||||
return (
|
||||
'{}\n{}'.format(
|
||||
markdown.setext_heading('Fermentables', level=2),
|
||||
markdown.table(headers, rows)
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def hops(self):
|
||||
"""Return markdown to represent the recipe's hops."""
|
||||
|
|
|
|||
|
|
@ -85,6 +85,28 @@ def test_recipe_details(md_weizen):
|
|||
assert '**Batch size**: 20.8 L' in md_weizen.details
|
||||
|
||||
|
||||
def test_recipe_fermentables(md_weizen):
|
||||
"""Test valid fermentable table is generated."""
|
||||
md_weizen.fermentable_unit = 'pounds'
|
||||
assert md_weizen.fermentables == (
|
||||
'Fermentables\n'
|
||||
'------------\n'
|
||||
'| Name | Type | Color | Amount |\n'
|
||||
'| --------------- | --------- | ------ | ------- |\n'
|
||||
'| Pilsner (DE) | Base Malt | 1.0 °L | 5.00 lb |\n'
|
||||
'| Wheat Malt (DE) | Adjunct | 2.0 °L | 5.00 lb |'
|
||||
)
|
||||
|
||||
md_weizen.fermentable_unit = 'ounces'
|
||||
assert '| 80.0 oz |' in md_weizen.fermentables
|
||||
|
||||
md_weizen.fermentable_unit = 'grams'
|
||||
assert '| 2268.0 g |' in md_weizen.fermentables
|
||||
|
||||
md_weizen.fermentable_unit = 'kilograms'
|
||||
assert '| 2.27 kg |' in md_weizen.fermentables
|
||||
|
||||
|
||||
def test_recipe_hops(md_weizen):
|
||||
"""Test valid hop table is generated."""
|
||||
md_weizen.hop_unit = 'ounces'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue