7.3. Using recipes

Once created, you may use a Recipe XML file just as you would use any other Pantry file. There is one exception to this though: Recipe XML files are read-only. Thus, although you may search Recipe XML files just as you would any other Pantry file, you may not add foods to them using Pantry. (You may of course add foods using your text editor, which is what we have been discussing in this section.)

When Pantry reads in recipes from a Recipe XML file, it first finds all the ingredients in the specified foodSource file. It then calculates the total nutrient breakdown of all the ingredients, before dividing the recipe into portions using any information given in the yield element. Pantry then creates a food in the buffer that has the appropriate traits, available units, and nutrients. After the food is in the buffer, it is indistinguishable from other Pantry foods. This means that Pantry no longer knows what ingredients the food contains, though this information remains in the Recipe XML file.

Doing all this searching and calculating takes a little while. The time is not noticeaeble for a few recipes, but it could be noticeable for several recipes. In addition, you'll probably find it more convenient if your recipes are in a file with all the other foods you use. Thus, you will probably find it most convenient to add your new foods to a Pantry native file, such as the master file or a quick file.

Example 7.6. Using a Recipe XML file

$ pantry --name "Easy Corn Bread" --print traits-units-nuts \
> recipes.xml
Easy Corn Bread
Group: Baked Products
1 serving (76g)
   serving
Nutrient                  Amount         %G     %TOT  
------------------------------------------------------
Calories                  208  kcal       10     100   
Total Fat                 8    g          12     100   
Saturated Fat             1    g          5      100   
Cholesterol               26   mg         9      100   
Sodium                    234  mg         10     100   
Total Carbohydrate        31   g          10     100   
Dietary Fiber             1    g          6      100   
Sugars                    7    g          NG     100   
Protein                   4    g          9      100   
Vitamin A                 106  IU         2      100   
Vitamin C                 0    mg         0      100   
Calcium                   114  mg         11     100   
Iron                      1    mg         8      100   

Example 7.7. Adding a recipe to a Pantry native file

$ pantry --add master recipes.xml
$ pantry --name "Easy Corn Bread" --print names master
Easy Corn Bread