Chapter 3. Using Pantry: practical examples
Prev |  | Next

## Chapter 3. Using Pantry: practical examples

Now that you know all the basic Pantry options, you're ready to combine them and put them to use! This chapter will show you how.

## 3.1. Finding nutrient amounts

Often you will wish to know the nutrient makeup of a particular food. Suppose for example that you want to know how many calories are in a fresh apple. You figure that `master` already has such a food, but you don't know exactly what it would be. So first you search for `apple` to see what comes up.

Example 3.1. Searching for apples

    $ pantry --ignore-case --name apple --print names master
    Babyfood, fruit, bananas and pineapple with tapioca, junior
    Apples, canned, sweetened, sliced, drained, heated
    Fast foods, burrito, with fruit (apple or cherry)
    Babyfood, fruit, applesauce and apricots, strained
    Cereals ready-to-eat, GENERAL MILLS, OATMEAL CRISP, APPLE CINNAMON
    HEALTHY CHOICE Country Roasted Turkey w/Cranberry Apple Sauce, Green Beans & Carrot Blend
    Danish pastry, fruit, enriched (includes apple, cinnamon, raisin, lemon, raspberry, strawberry)
    Pineapple, canned, water pack, solids and liquids
    PEPPERIDGE FARM Apple Turnovers, frozen, ready to bake
    Babyfood, fruit, bananas with apples and pears, strained
    Apples, dried, sulfured, stewed, with added sugar
    Apples, raw, with skin
    Fruit cocktail, (peach and pineapple and pear and grape and cherry), canned, extra light syrup, solids and liquids
    Babyfood, juice, apple-sweet potato
    Babyfood, apple-banana juice
    [ trimmed to save space ]

It turns out that this search returns 163 results. There must be a way to narrow this down. Well, many foods will have the word "Apple" in their name, including many foods that are not even fruits (desserts, for example). A good way to narrow your results is to use the `--group` option:

Example 3.2. Searching for apples, with the `--group` option

    $ pantry --ignore-case --name apple --group fruits --print names master
    Apples, raw, without skin, cooked, microwave
    Sugar-apples, (sweetsop), raw
    Apple juice, canned or bottled, unsweetened, with added ascorbic acid
    Pineapple, canned, juice pack, solids and liquids
    Apples, canned, sweetened, sliced, drained, heated
    Crabapples, raw
    Fruit salad, (peach and pear and apricot and pineapple and cherry), canned, water pack, solids and liquids
    Apples, frozen, unsweetened, unheated
    Applesauce, canned, unsweetened, without added ascorbic acid
    Fruit salad, (peach and pear and apricot and pineapple and cherry), canned, heavy syrup, solids and liquids
    Apples, raw, without skin
    Applesauce, canned, sweetened, with salt
    Apple juice, frozen concentrate, unsweetened, diluted with 3 volume water without added ascorbic acid
    Fruit cocktail, (peach and pineapple and pear and grape and cherry), canned, juice pack, solids and liquids
    Pineapple, canned, extra heavy syrup pack, solids and liquids
    [ trimmed to save space ]

That is still a lot more than we are looking for, including a bunch of things that merely have "Apple" in their name. What if we use a regular expression to limit the results only to foods whose `name` trait begins with `apple`?

Example 3.3. Searching for apples using a regular expression

    $ pantry --ignore-case --name ^apple --group fruits --print names master
    Apples, raw, without skin, cooked, microwave
    Apple juice, canned or bottled, unsweetened, with added ascorbic acid
    Apples, canned, sweetened, sliced, drained, heated
    Apples, frozen, unsweetened, unheated
    Applesauce, canned, unsweetened, without added ascorbic acid
    Apples, raw, without skin
    Applesauce, canned, sweetened, with salt
    Apple juice, frozen concentrate, unsweetened, diluted with 3 volume water without added ascorbic acid
    Apples, dried, sulfured, stewed, with added sugar
    Apples, raw, with skin
    Apples, dried, sulfured, uncooked
    Apple juice, frozen concentrate, unsweetened, undiluted, with added ascorbic acid
    Apples, canned, sweetened, sliced, drained, unheated
    Apple juice, frozen concentrate, unsweetened, undiluted, without added ascorbic acid
    Apples, frozen, unsweetened, heated
    Apples, dehydrated (low moisture), sulfured, stewed
    Apples, dried, sulfured, stewed, without added sugar
    Applesauce, canned, sweetened, without salt
    Apples, raw, without skin, cooked, boiled
    Applesauce, canned, unsweetened, with added ascorbic acid
    Apples, dehydrated (low moisture), sulfured, uncooked
    Apple juice, canned or bottled, unsweetened, without added ascorbic acid
    Apple juice, frozen concentrate, unsweetened, diluted with 3 volume water, with added ascorbic acid

That buffer is manageable enough to scan to see what we are looking for. Looks like `Apples, raw, with skin` is what we are looking for. We want to know how many calories are in an apple. To do that, first we need to see what units are available for `Apples, raw, with skin`:

Example 3.4. Available units for an apple

    $ pantry --name "Apples, raw, with skin" --print names-units \
    > master
    Apples, raw, with skin
       cup, quartered or chopped
       medium (3" dia)
       extra small (2-1/2" dia)
       large (3-1/4" dia)
       NLEA serving
       small (2-3/4" dia)
       cup slices

Notice how we combined the `names` and `units` reports rather than using just a `units` report. This is a good idea because otherwise, your report might actually contain results for more than one food, but you would not know this if you used only a `units` report.

Finally, we use the change options to take the apple from the `master` file, change it to the characteristics we're interested in, and print a report:

Example 3.5. How many calories are in an apple?

    $ pantry --name "Apples, raw, with skin" --c-unit large \
    > --c-qty 1 --print traits-nuts master
    Apples, raw, with skin
    Group: Fruits and Fruit Juices
    Refuse: 10 percent Core and stem
    1 large (3-1/4" dia) (223g)
    Nutrient                  Amount         %G     %TOT
    -------------------------------------------------------
    Calories                  116  kcal       6      100
    Total Fat                 0    g          1      100
    Saturated Fat             0    g          0      100
    Cholesterol               0    mg         0      0
    Sodium                    2    mg         0      100
    Total Carbohydrate        31   g          10     100
    Dietary Fiber             5    g          21     100
    Sugars                    23   g          NA     100
    Protein                   1    g          1      100
    Vitamin A                 120  IU         2      100
    Vitamin C                 10   mg         17     100
    Calcium                   13   mg         1      100
    Iron                      0    mg         1      100

Prev |  | Next
2.8. Saving new foods with `--add` and `--edit`; deleting with the `--delete` option | Home | 3.2. Keeping a food diary