Pantry would not be very useful if you could only
search the master for its contents
and print results from it. Fortunately, Pantry makes it
very easy for you to change the traits of foods.
When you run pantry with the
search options we discussed above,
pantry first searches the files you
specified for foods with the traits you specified with
your options. pantry then changes
the resulting foods to the traits you specify, as we
will discuss next. For instance, in the next example we
change the date trait of a raw
banana. However, as the example also shows, the change
is only temporary. Only the food in the buffer is
changed, and the food in the buffer is a copy of the
food in the master file. Later we
will learn how to save the new foods that you make.
Example 2.14. Changing foods
$pantry --name "Bananas, raw" --print traits masterBananas, raw Group: Fruits and Fruit Juices Refuse: 36 percent Skin 100 g (100g)
$pantry --name "Bananas, raw" --c-date "2007-05-06" \>--print traits masterBananas, raw Group: Fruits and Fruit Juices Date: 2007-05-06 Refuse: 36 percent Skin 100 g (100g)
$pantry --name "Bananas, raw" --print traits masterBananas, raw Group: Fruits and Fruit Juices Refuse: 36 percent Skin 100 g (100g)
There are eight options you use to change food traits. Each takes an argument to indicate what you would like to change the trait to:
--c-name or
-N
--c-group or
-G
--c-date or
-D
--c-meal or
-M
--c-comment or
-C
--c-unit or
-U
--c-qty or
-Q
--c-order or
-O
Changing most
traits is easy, as you may change them to any string that
you wish, including a zero-length string. This gives you
a great deal of flexibility. The
group trait need not be set to a
"official" food group. The
date trait does not need to respect
any particular date format--indeed, strictly speaking,
it need not be any date at all!
Only two traits are not this flexible. As with the
other traits, Pantry stores the qty
trait as a string, but it is converted internally to a
number as needed, so the value of this trait must be
something that can be converted to a number. It can be an integer, a
floating-point number, or even a fraction or mixed
number. Thus, the following values are valid for the
qty trait:
3
1/3
3 1/3
3.33
Entering zero for the qty trait
does not delete foods; later we'll
discuss how to delete foods.
The other inflexible trait is the
unit trait. This trait must be equal
to one of the available units for each particular food.
The argument that the --c-unit takes is
actually a regular expression. pantry
searches the food's available units for a single unit
matching that regular expression.
Example 2.15. Changing the unit trait
$pantry --name "Bananas, raw" --c-date "May 7" \>--c-qty 2 --c-unit medium --print traits-nuts masterBananas, raw Group: Fruits and Fruit Juices Date: May 7 Refuse: 36 percent Skin 2 medium (7" to 7-7/8" long) (236g) Nutrient Amount %G %TOT ------------------------------------------------------- Calories 210 kcal 11 100 Total Fat 1 g 1 100 Saturated Fat 0 g 1 100 Cholesterol 0 mg 0 0 Sodium 2 mg 0 100 Total Carbohydrate 54 g 18 100 Dietary Fiber 6 g 25 100 Sugars 29 g NA 100 Protein 3 g 5 100 Vitamin A 151 IU 3 100 Vitamin C 21 mg 34 100 Calcium 12 mg 1 100 Iron 1 mg 3 100
If the regular expression you enter as an argument
for --c-unit matches more than one of a
food's available units, pantry will
give you a warning message. pantry
will not include the food (either changed or unchanged)
in the search results; therefore, the food will not be
printed in any reports you may have asked for using the
--print option. However, Pantry will
still include in the search results other foods that it
did change. In the next example, the food
Bananas, raw cannot have its
units changed, because the search string
cup matches more than one of the
food's available units. However, the food
Bananas, dehydrated, or banana
powder is included in the search results
because its unit was successfully changed.
Example 2.16. Errors when changing the unit trait
$pantry --name "Bananas," --print traits-units masterBananas, dehydrated, or banana powder Group: Fruits and Fruit Juices 100 g (100g) cup tbsp Bananas, raw Group: Fruits and Fruit Juices Refuse: 36 percent Skin 100 g (100g) cup, mashed large (8" to 8-7/8" long) medium (7" to 7-7/8" long) extra small (less than 6" long) small (6" to 6-7/8" long) NLEA serving cup, sliced extra large (9" or longer)
$pantry --name "Bananas," --c-unit cup --print traits-units \>master========== pantry: warning: food Bananas, raw will not be copied into the buffer. More than one matching unit for --c-unit argument cup. Matches: cup, mashed cup, sliced ========== Bananas, dehydrated, or banana powder Group: Fruits and Fruit Juices 100 cup (10000g) cup tbsp
As we discussed, you can use fractions and mixed
numbers for the qty trait:
Example 2.17. qty may be a fraction or mixed
number
$pantry --name "Bananas, raw" --c-qty "1/2" \>--c-unit medium --print traits-nuts masterBananas, raw Group: Fruits and Fruit Juices Refuse: 36 percent Skin 1/2 medium (7" to 7-7/8" long) (59g) Nutrient Amount %G %TOT ------------------------------------------------------- Calories 53 kcal 3 100 Total Fat 0 g 0 100 Saturated Fat 0 g 0 100 Cholesterol 0 mg 0 0 Sodium 1 mg 0 100 Total Carbohydrate 13 g 4 100 Dietary Fiber 2 g 6 100 Sugars 7 g NA 100 Protein 1 g 1 100 Vitamin A 38 IU 1 100 Vitamin C 5 mg 9 100 Calcium 3 mg 0 100 Iron 0 mg 1 100
$pantry --name "Bananas, raw" --c-qty "2 1/2" \>--c-unit medium --print traits-nuts masterBananas, raw Group: Fruits and Fruit Juices Refuse: 36 percent Skin 2 1/2 medium (7" to 7-7/8" long) (295g) Nutrient Amount %G %TOT ------------------------------------------------------- Calories 263 kcal 13 100 Total Fat 1 g 1 100 Saturated Fat 0 g 2 100 Cholesterol 0 mg 0 0 Sodium 3 mg 0 100 Total Carbohydrate 67 g 22 100 Dietary Fiber 8 g 31 100 Sugars 36 g NA 100 Protein 3 g 6 100 Vitamin A 189 IU 4 100 Vitamin C 26 mg 43 100 Calcium 15 mg 1 100 Iron 1 mg 4 100