Example #1
0
    def get_color_metrics(self, color_value):
        # If it's numeric, it's SRM
        if isinstance(color_value, float) or isinstance(color_value, int):
            return color_value, None

        # If it's a string, check for units
        if isinstance(color_value, str):
            color_value = color_value.strip().lower()
            if color_value.endswith('ebc'):
                ebc = float_or_none(color_value.replace('ebc', '').strip())
                return None, ebc
            elif color_value.endswith('srm'):
                srm = float_or_none(color_value.replace('srm', '').strip())
                return srm, None

        return None, None
Example #2
0
    def get_abv(self, beerxml: BeerXMLRecipe):
        abv = beerxml.abv
        if isinstance(abv, str):
            abv = float_or_none(self.strip_abv_unit(abv))

        if isinstance(abv, float):
            return abv

        return None
Example #3
0
 def float_or_none(self, child_name):
     child_name = child_name.lower()
     child_node = self.get_child(child_name)
     if child_node:
         return float_or_none(child_node.text)
     return None