Commiting

This commit is contained in:
Brian Buller 2017-11-24 05:12:52 -06:00
parent 822f30394a
commit 2bb253e1a3
2 changed files with 23 additions and 11 deletions

View File

@ -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()
}

View File

@ -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)
}
}