brew.parsers¶
-
class
brew.parsers.
DataLoader
(data_dir)¶ Base class for loading data from data files inside the data_dir.
Parameters: data_dir (str) – The directory where the data resides -
DATA
= {}¶
-
EXT
= ''¶
-
classmethod
format_name
(name)¶ Reformat a given name to match the filename of a data file.
-
get_item
(dir_suffix, item_name)¶ Parameters: - dir_suffix (str) – The directory name suffix
- item_name (str) – The name of the item to load
Returns: The item as a python dict
Raises: - DataLoaderException – If item directory does not exist
- Warning – If item not found in the directory
-
classmethod
read_data
(filename)¶ Parameters: filename (str) – The filename of the file to read Raises: NotImplementedError – Must be supplied in inherited class
-
-
class
brew.parsers.
JSONDataLoader
(data_dir)¶ Load data from JSON files inside the data_dir.
Parameters: data_dir (str) – The directory where the data resides -
DATA
= {}¶
-
EXT
= 'json'¶
-
format_name
(name)¶ Reformat a given name to match the filename of a data file.
-
get_item
(dir_suffix, item_name)¶ Parameters: - dir_suffix (str) – The directory name suffix
- item_name (str) – The name of the item to load
Returns: The item as a python dict
Raises: - DataLoaderException – If item directory does not exist
- Warning – If item not found in the directory
-
classmethod
read_data
(filename)¶ Parameters: filename (str) – The filename of the file to read Returns: The data loaded from a JSON file
-
-
parsers.
parse_cereals
(cereal, loader, dir_suffix='cereals/')¶ Parse grains data from a recipe
Parameters: - cereal (dict) – A representation of a cereal
- loader (DataLoader) – A class to load additional information
Grain must have the following top level attributes:
- name (str)
- weight (float)
- data (dict) (optional)
Additionally grains may contain override data in the ‘data’ attribute with the following keys:
- color (float)
- ppg (int)
-
parsers.
parse_hops
(hop, loader, dir_suffix='hops/')¶ Parse hops data from a recipe
Parameters: - hops (dict) – A representation of a hop
- loader (DataLoader) – A class to load additional information
Hops must have the following top level attributes:
- name (str)
- weight (float)
- boil_time (float)
- data (dict) (optional)
Additionally hops may contain override data in the ‘data’ attribute with the following keys:
- percent_alpha_acids (float)
-
parsers.
parse_yeast
(yeast, loader, dir_suffix='yeast/')¶ Parse yeast data from a recipe
Parameters: - hops (dict) – A representation of a yeast
- loader (DataLoader) – A class to load additional information
Yeast must have the following top level attributes:
- name (str)
- data (dict) (optional)
Additionally yeast may contain override data in the ‘data’ attribute with the following keys:
- percent_attenuation (float)
-
parsers.
parse_recipe
(recipe, loader, cereals_loader=None, hops_loader=None, yeast_loader=None, cereals_dir_suffix='cereals/', hops_dir_suffix='hops/', yeast_dir_suffix='yeast/')¶ Parse a recipe from a python Dict
Parameters: - recipe (dict) – A representation of a recipe
- loader (DataLoader) – A class to load additional information
- cereal_loader (DataLoader) – A class to load additional information specific to cereals
- hops_loader (DataLoader) – A class to load additional information specific to hops
- yeast_loader (DataLoader) – A class to load additional information specific to yeast
A recipe must have the following top level attributes:
- name (str)
- start_volume (float)
- final_volume (float)
- grains (list(dict))
- hops (list(dict))
- yeast (dict)
Additionally the recipe may contain override data in the ‘data’ attribute with the following keys:
- brew_house_yield (float)
- units (str)
All other fields will be ignored and may be used for other metadata.
The dict objects in the grains, hops, and yeast values are required to have the key ‘name’ and the remaining attributes will be looked up in the data directory if they are not provided.