diff --git a/main.go b/main.go index 95401a8..0b484fd 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,9 @@ package main -import "fmt" - func main() { - r := Recipe{Name:"Bread"} - fmt.Println("Done: "+r.Name) + ml := NewRecipe("Mint Lassi") + for _, v := range []string{"Fire Shard", "Water Shard", "Galago Mint", "Aldgoat Milk"} { + ml.AddIngredient(&Ingredient{Name: v}, 1) + } + ml.FancyPrint() } diff --git a/recipes.go b/recipes.go index 6cff260..d5ce9c0 100644 --- a/recipes.go +++ b/recipes.go @@ -1,5 +1,7 @@ package main +import "fmt" + type Ingredient struct { Name string Parts []Ingredient @@ -20,25 +22,34 @@ type Recipe struct { func NewRecipe(nm string) *Recipe { ret := Recipe{Name: nm} + return &ret } func (r *Recipe) AddNote(nt string) { r.Notes = append(r.Notes, nt) } -func (r *Recipe) AddIngredient(i *Ingredient, qty int) { +func (r *Recipe) AddIngredient(nIng *Ingredient, qty int) { for i := range r.Parts { - if r.Parts[i].Name == i.Name { + if r.Parts[i].Name == nIng.Name { // This ingredient is already a party of the recipe + // Just increase the quantity r.Parts[i].Quantity += qty return } } ing := new(RecipeIngredient) - ing.Name = i.Name - ing.Parts = i.Parts - ing.Location = i.Location + ing.Name = nIng.Name + ing.Parts = nIng.Parts + ing.Location = nIng.Location ing.Quantity = qty - ing.Notes = i.Notes - r.Parts = append(r.Parts, ing) + ing.Notes = nIng.Notes + r.Parts = append(r.Parts, *ing) +} + +func (r *Recipe) FancyPrint() { + fmt.Println("= "+r.Name+" =") + for _, v := range r.Parts { + fmt.Printf("* %d - %s\n", v.Quantity, v.Name) + } }