For this project you will implement a small diet manager in Ruby. To do this your application will maintain a database of foods - both basic foods and recipes composed of other foods (both recipes and basic). In addition, your application will maintain a log of foods that the user consumes each day. Commands will allow users to add and delete foods, to log and unlog foods for a given date, to save the log and food database, and to print a variety of reports.
The food database is a simple text file, named FoodDB.txt. The file has one text line per food, with the food and associated information in CSV format. There are two types of lines, representing the two types of food, basic and recipe:
name,b,calories
name,r,name,name,...,name
The first form, identified by a "b" in the second column, is a basic food. All we record for such foods are the name and the calories by unit serving. The second form, identified by an "r" in the second column, is a recipe. In this case, the third and following fields name the constituent foods in the recipe (if a given food is used in multiple units then it is simply listed multiple times).
The diet log is also a simple CSV formatted text file, named DietLog.txt, with one line per food item logged; it is perfectly legitimate to have the same food listed multiple times for a given day. The log lines each have two fields: a date and a food name. Obviously, the food names must exist in the database. Take a look at the date oriented objects in the Ruby libraries.
12/26/1996,Wheat Bread
4/15/2004,PB&J Sandwich
9/12/2008,Apple
12/6/2009,Jelly
2/8/2011,Orange
quit
Saves the food database and the log (if they've changed) and exits. This also occurs if the program encounters end of file.
save
Saves the food database and log (if changed) without exiting.
new food name,calories
Saves a new basic food and its calories. Reports an error and does nothing if a food of the given name is already in the database.
new recipe name,name1,...,nameN
Saves a new recipe name consisting of the N named foods that follow. If name is already in the database, or if any of the N constituent food names are not in the database, report an error and do nothing.
print name
Prints basic information on the named food (if there is no
such food, print an error message and do nothing)
For a basic food, simply print the food name and the calories:
>print orange
Orange 67
For recipes, the constituents are printed out hierarchically, using as many
levels as required.
>print PB&J Sandwich
PB&J Sandwich 490
Bread Slice 80
Bread Slice 80
Jelly 155
Peanut Butter 175
print all
Prints information on all the foods and recipes in the database, using the format shown below:
>print all
Orange 67
Bread Slice 80
Peanut Butter 175
Jelly 155
Apple 50
Wheat Bread 50
Chicken 245
Chicken Sandwich 405
Bread Slice 80
Bread Slice 80
Chicken 245
PB&J Sandwich 490
Bread Slice 80
Bread Slice 80
Jelly 155
Peanut Butter 175
find prefix
Prints information on all the foods in the database that begin with the given prefix. In matching the prefix, the case of the letters is ignored.
>find Ora
Orange 67
log name
Adds one unit of the named food to the log for today. Simply prints a message if the food is not in the database.
log name,date
Adds one unit of the named food to the log for the specified date. Simply prints a message if the food is not in the database.
delete name,date
Removes one unit of the named food from the log for the given date. Does nothing if the food is not in the log on that date.
show
Shows the log of foods for today. If a food occurs several times, it is printed just once with the number of units following the name in parentheses.
show date
Shows the log of foods for the given date as with plain show above.
show all
Shows the log of foods for all dates in the log, organized by ascending date. The log for each day is preceded by a line with the day's date.
Download and extract the starter files in the DietManager.zip file. Make sure all files reside in the DietManager directory in your GitLab repo.The starter files include:
The product and corresponding unit test classes you are to complete:
FoodDB.rb / FoodDBTest.rb
BasicFood.rb /BasicFoodTest.rb
Recipe.rb / RecipeTest.rb
Log.rb / LogTest.rb
LogItem.rb / LogItemTest.rb
The skelelton driver program for accepting and processing user commands:
DietManager.rb
The initial CSV files representing the FoodDB and DietLog:
FoodDB.txt
DietLog.txt
Submit your work to the DietManager directory at the top of your repository.
Complete the five product and unit test classes. Each pair of product/test classes are worth 9 points. Note that some code has been provided for you in both the product and test classes. Your product classes will be tested using our unit tests. You may create additional unit tests or methods within the classess - but do not change or remove any existing class, variable or method names
Complete the DietManger.rb driver class which accepts and processes command input from standard input (keyboard or file). To encourage incremental development there are 5 levels of submissions. You may stop at any level and receive up to the cumulative grade at that point, but you must have submitted an entry for all preceding levels. Each completed level is woth 9 points.
When you have completed a level use the commit message "*** Level n
Complete ***" before starting the next level. Only your last
completed level will be graded, but your git log must demonstrate that you
developed and tested the application incrementally to receive full credit.
At this level, the program can read the FoodDB.txt file, parse the CSV lines, and build up the internal food database. The commands supported are quit and print all.
For this level you will enhance Level 1 by implementing the print name and find prefix commands.
For this level you will add the commands that can update the database: new food, new recipe, save, and the change to quit to check for modification before exiting.
For this level you will add support for the log name and log name,date commands, as well as show all.
This is the last level, where you will add support for show, show date, and delete name,date.
Effective use of source control - frequency of submissions, quality of commit messages.
Clear, concise, and correct comments before classes, methods, and significant blocks of code.
Consistent indentation following the Ruby conventions (2 space indentation).
As in previous projects, you are expected to estimate and track your effort for as many of the levels as you complete, using this Activity Journal.
To avoid confusion please refer to this sample output. You can assume that correct input is given for all commands.