From 39318f8ed1d9a0e9a5f493040f50993175dd047f Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Mon, 31 Dec 2018 11:19:44 -0700 Subject: [PATCH] Add mash steps --- src/synthale/recipes.py | 41 +++++++++++++++++++++++++++++++++++++++-- tests/test_recipes.py | 11 +++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/synthale/recipes.py b/src/synthale/recipes.py index 8f1006f..28b4a7e 100644 --- a/src/synthale/recipes.py +++ b/src/synthale/recipes.py @@ -16,13 +16,15 @@ class MarkdownRecipe: recipe, vol_unit='gallons', hop_unit='ounces', - fermentable_unit='pounds'): + fermentable_unit='pounds', + temp_unit='fahrenheit'): """Create a MarkdownRecipe object. `recipe` is a recipe object from the pybeerxml package. `vol_unit` specifies the unit for boil size and batch size. Can be one - of 'gallons', or 'liters'. + of 'gallons', or 'liters'. If specified unit is not matched, default is + 'liters'. `hop_unit` specifies the unit for hop amounts. Can be one of 'ounces', 'pounds', 'grams', or 'kilograms'. If specified unit is not @@ -31,11 +33,16 @@ class MarkdownRecipe: `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'. + + `temp_unit` specifies the unit for temperatures. Can be one of + 'fahrenheit' or 'celsius'. If specified unit is not matched, default is + 'fahrenheit'. """ self.recipe = recipe self.vol_unit = vol_unit self.hop_unit = hop_unit self.fermentable_unit = fermentable_unit + self.temp_unit = temp_unit @property def filename(self): @@ -71,6 +78,8 @@ class MarkdownRecipe: '', self.miscs, '', + self.mash, + '', )) @property @@ -223,6 +232,34 @@ class MarkdownRecipe: ) ) + @property + def mash(self): + """Return the markdown to represent the recipe's mash steps.""" + headers = ('Name', 'Type', 'Temperature', 'Time', 'Amount') + rows = [] + for step in self.recipe.mash.steps: + if self.temp_unit == 'celsius': + temp = convert.celsius(step.step_temp, '.1f') + else: + temp = convert.fahrenheit(step.step_temp, '.1f') + if self.vol_unit == 'gallons': + amt = convert.gallons(step.infuse_amount, '.1f') + else: + amt = convert.liters(step.infuse_amount, '.1f') + rows.append(( + step.name, + step.type, + temp, + '{} min'.format(int(step.step_time)), + amt + )) + return ( + '{}\n{}'.format( + markdown.setext_heading('Mash', level=2), + markdown.table(headers, rows) + ) + ) + def load_file(path): """Parse BeerXML file located at `path`. diff --git a/tests/test_recipes.py b/tests/test_recipes.py index 2e97f61..42221d3 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -169,6 +169,17 @@ def test_recipe_miscs(md_coffee_stout): ) +def test_recipe_mash(md_coffee_stout): + """Test valid recipe mash table.""" + assert md_coffee_stout.mash == ( + 'Mash\n' + '----\n' + '| Name | Type | Temperature | Time | Amount |\n' + '| -------- | -------- | ----------- | ------ | -------- |\n' + '| Infusion | Infusion | 152.0 °F | 60 min | 37.55 lb |' + ) + + def test_write_recipes(md_recipes, tmpdir): """Test write_recipes function.""" write_recipes(md_recipes, str(tmpdir))