🍕🔥 Pizza is great! 🔥🍕

Ingredient Manipulation

The ingredient manipulation module provides tools for creating, modifying, and analyzing virtual ingredients in TomatoPy.

Creating Ingredients

Basic Ingredient Creation

from tomatopy import Ingredient

# Create a basic ingredient
tomato = Ingredient(
    name="tomato",
    amount=1,
    unit="whole",
    properties={
        "ripeness": 0.8,
        "water_content": 0.95,
        "sugar_content": 0.03
    }
)

Specialized Ingredient Classes

from tomatopy import Tomato, Garlic, Basil

# Create specialized ingredients
san_marzano = Tomato(
    ripeness=0.8,
    variety="San Marzano",
    weight=150
)

fresh_garlic = Garlic(
    cloves=3,
    freshness=0.9,
    size="medium"
)

sweet_basil = Basil(
    leaves=10,
    freshness=0.95,
    variety="Genovese"
)

Modifying Ingredients

Property Updates

# Update ingredient properties
tomato.properties["ripeness"] = 0.9
tomato.properties["water_content"] = 0.92

# Batch update properties
tomato.update_properties({
    "ripeness": 0.9,
    "water_content": 0.92,
    "sugar_content": 0.04
})

Unit Conversion

# Convert between units
tomato.convert_to_imperial()  # Converts metric to imperial
tomato.convert_volume("ml", "cups")  # Converts between volume units

# Get measurements in different units
print(tomato.get_weight("g"))  # 150
print(tomato.get_weight("oz"))  # 5.29

Ingredient Analysis

Physical Properties

# Get physical properties
print(tomato.get_density())  # 1.02 g/ml
print(tomato.get_volume())   # 147 ml
print(tomato.get_surface_area())  # 150 cm²

Chemical Analysis

# Analyze chemical properties
print(tomato.get_ph())  # 4.5
print(tomato.get_water_content())  # 0.95
print(tomato.get_sugar_content())  # 0.03

Ingredient Operations

Cutting and Chopping

# Cut ingredients
diced_tomato = tomato.cut(
    method="dice",
    size="medium",
    consistency="uniform"
)

# Chop ingredients
chopped_garlic = fresh_garlic.chop(
    fineness="medium",
    method="mince"
)

Combining Ingredients

# Combine ingredients
mixture = tomato.combine(
    fresh_garlic,
    sweet_basil,
    method="mix",
    consistency="chunky"
)

Quality Control

Freshness Check

# Check ingredient freshness
if tomato.is_fresh():
    print("Ingredient is fresh")
else:
    print("Ingredient may be past its prime")

# Get freshness score
freshness_score = tomato.get_freshness_score()  # 0.85

Quality Assessment

# Assess ingredient quality
quality_report = tomato.assess_quality()
print(quality_report.overall_score)  # 0.92
print(quality_report.recommendations)  # ["Consider using within 2 days"]

Error Handling

try:
    # Attempt invalid operation
    tomato.cut(method="invalid_method")
except IngredientError as e:
    print(f"Error: {e}")  # "Invalid cutting method"

try:
    # Attempt invalid property update
    tomato.update_properties({"invalid_property": 1.0})
except PropertyError as e:
    print(f"Error: {e}")  # "Invalid property name"

Best Practices

  1. Always Check Ingredient State

    if tomato.state == "fresh":
        # Proceed with operation
  2. Use Type Hints

    from typing import Dict, Any
    
    def create_ingredient(
        name: str,
        properties: Dict[str, Any]
    ) -> Ingredient:
        return Ingredient(name=name, properties=properties)
  3. Handle Unit Conversions Carefully

    # Always specify units explicitly
    weight_grams = tomato.get_weight("g")
    weight_ounces = tomato.get_weight("oz")

API Reference

Classes

  • Ingredient: Base class for all ingredients

  • Tomato: Specialized tomato ingredient

  • Garlic: Specialized garlic ingredient

  • Basil: Specialized basil ingredient

Methods

Ingredient Class

  • __init__(name, amount, unit, properties)

  • update_properties(properties)

  • convert_to_imperial()

  • convert_volume(from_unit, to_unit)

  • get_density()

  • get_volume()

  • get_surface_area()

  • get_ph()

  • get_water_content()

  • get_sugar_content()

  • cut(method, size, consistency)

  • chop(fineness, method)

  • combine(*ingredients, method, consistency)

  • is_fresh()

  • get_freshness_score()

  • assess_quality()

Next Steps

Last updated

Was this helpful?