Ejemplo n.º 1
0
    def hops(self):
        """Return markdown to represent the recipe's hops."""
        headers = ('Name', 'Origin', 'Alpha', 'Amount', 'Time', 'Use')
        rows = []
        for hop in self.recipe.hops:
            # Determine hop unit
            if self.hop_unit == 'pounds':
                amt = convert.pounds(hop.amount, '.2f')
            elif self.hop_unit == 'grams':
                amt = convert.grams(hop.amount, '.1f')
            elif self.hop_unit == 'kilograms':
                amt = convert.kilograms(hop.amount, '.2f')
            else:
                amt = convert.ounces(hop.amount, '.1f')

            # Determine hop timing
            if hop.use == 'Dry Hop':
                # 1 day = 1440 minutes
                time = '{:.1f} days'.format(hop.time / 1440.0)
            else:
                time = '{} min'.format(int(round(hop.time)))
            rows.append((
                hop.name,
                hop.origin,
                '{:.1f} %'.format(hop.alpha),
                amt,
                time,
                hop.use,
            ))
        return ('{}\n{}'.format(markdown.setext_heading('Hops', level=2),
                                markdown.table(headers, rows)))
Ejemplo n.º 2
0
 def yeast(self):
     """Return markdown to represent the recipe's yeast."""
     headers = ('Name', 'Lab', 'Type', 'Attenuation')
     rows = []
     for yeast in self.recipe.yeasts:
         rows.append((
             yeast.name,
             yeast.laboratory,
             yeast.type,
             '{:.1f} %'.format(yeast.attenuation),
         ))
     return ('{}\n{}'.format(markdown.setext_heading('Yeast', level=2),
                             markdown.table(headers, rows)))
Ejemplo n.º 3
0
    def miscs(self):
        """Return the markdown to represent the recipe's other ingredients."""
        if len(self.recipe.miscs) == 0:
            return ''

        headers = ('Name', 'Use', 'Amount')
        rows = []
        for misc in self.recipe.miscs:
            if misc.display_amount is not None:
                amt = str(misc.display_amount)
            elif misc.amount_is_weight:
                amt = '{:.2f} kg'.format(misc.amount)
            else:
                amt = '{:.2f} L'.format(misc.amount)
            rows.append((misc.name, misc.use, amt))
        return ('{}\n{}'.format(
            markdown.setext_heading('Other Ingredients', level=2),
            markdown.table(headers, rows)))
Ejemplo n.º 4
0
 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)))
Ejemplo n.º 5
0
    def mash(self):
        """Return the markdown to represent the recipe's mash steps."""
        if self.recipe.mash is None:
            return ''

        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)))
Ejemplo n.º 6
0
def test_table(headers, rows, expected):
    """Test table generation."""
    assert markdown.table(headers, rows) == expected