Recipe Scaler
Build a Ruby command-line tool that resizes recipes: tell it a recipe serves 4 and you want to cook for 6, and it recalculates every ingredient, then prints a tidy, readable list. It understands fractions as cooks write them (1/2 cup, 1 1/2 tsp), keeps amounts in friendly fractions instead of long decimals, and switches to a better unit when a number gets awkward (for example 16 tablespoons becomes 1 cup). Recipes are read from simple text or YAML files. It's a good first Ruby project: you'll learn Ruby classes and methods, exact fractions with Rational, parsing text with regular expressions, reading files, command-line options with OptionParser, and testing with Minitest.
- Estimate
- ~7.5h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
Ruby · OptionParser · Minitest
Project roadmap
- 01
Define the recipe format
~1hWrite README.md with an example recipe file in YAML: a title, the servings, and ingredients each with an amount (such as 1 1/2, 3/4, 2 or 0.5), a unit (cup, tbsp, tsp, g, kg, ml, l, or none, as in 2 eggs) and a name. Show the command (scale RECIPE --servings 6) and the exact output expected. Create a Gemfile with minitest. Done when: README.md shows the format, the command and the expected output.
- 02
Parse amounts and ingredients
~1.5hWrite an Amount parser that turns text like 1 1/2, 3/4, 2 and 0.5 into a Rational, using regular expressions, with a clear error for text it doesn't understand. Create an Ingredient class (amount, unit and name) and a Recipe class loaded from the YAML file, validating that servings is a positive whole number. Done when: unit tests show every amount format parses to the right Rational.
- 03
Scale the recipe
~1hAdd Recipe#scale(new_servings), which multiplies every amount by new_servings / servings as exact fractions and returns a new recipe, leaving the original unchanged. Ingredients without an amount (such as salt to taste) stay as they are. Done when: scaling from 4 to 6 servings multiplies every amount by 3/2 exactly.
- 04
Format amounts nicely
~1.5hPrint amounts as cooks write them: whole numbers, mixed fractions like 1 1/2, and fractions rounded to the nearest 1/8 for cups and spoons, while grams and millilitres are shown as whole numbers. Convert units when it reads better: 3 tsp or more becomes tablespoons, 16 tbsp becomes 1 cup, and 1,000 g becomes 1 kg. Done when: scaled recipes print friendly amounts like 2 1/4 cups instead of 2.25.
- 05
Build the command
~1hUse OptionParser for --servings (required, 1 to 100) and --help, read the recipe file given as an argument, and print the title, the new number of servings, and the ingredient list. Show clear messages for a missing file, invalid YAML, and bad amounts, and exit with code 1. Done when: the command in README.md prints exactly the expected output.
- 06
Test it
~1.5hWrite Minitest tests: parsing every amount format, scaling up and down (including to 1 serving), rounding to eighths, unit conversions, ingredients without amounts, and error messages for invalid input. Done when: ruby -Itest test/*_test.rb passes (or rake test).
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack