Commiting
This commit is contained in:
parent
822f30394a
commit
2bb253e1a3
9
main.go
9
main.go
@ -1,8 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
r := Recipe{Name:"Bread"}
|
ml := NewRecipe("Mint Lassi")
|
||||||
fmt.Println("Done: "+r.Name)
|
for _, v := range []string{"Fire Shard", "Water Shard", "Galago Mint", "Aldgoat Milk"} {
|
||||||
|
ml.AddIngredient(&Ingredient{Name: v}, 1)
|
||||||
|
}
|
||||||
|
ml.FancyPrint()
|
||||||
}
|
}
|
||||||
|
25
recipes.go
25
recipes.go
@ -1,5 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
type Ingredient struct {
|
type Ingredient struct {
|
||||||
Name string
|
Name string
|
||||||
Parts []Ingredient
|
Parts []Ingredient
|
||||||
@ -20,25 +22,34 @@ type Recipe struct {
|
|||||||
|
|
||||||
func NewRecipe(nm string) *Recipe {
|
func NewRecipe(nm string) *Recipe {
|
||||||
ret := Recipe{Name: nm}
|
ret := Recipe{Name: nm}
|
||||||
|
return &ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Recipe) AddNote(nt string) {
|
func (r *Recipe) AddNote(nt string) {
|
||||||
r.Notes = append(r.Notes, nt)
|
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 {
|
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
|
// This ingredient is already a party of the recipe
|
||||||
|
// Just increase the quantity
|
||||||
r.Parts[i].Quantity += qty
|
r.Parts[i].Quantity += qty
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ing := new(RecipeIngredient)
|
ing := new(RecipeIngredient)
|
||||||
ing.Name = i.Name
|
ing.Name = nIng.Name
|
||||||
ing.Parts = i.Parts
|
ing.Parts = nIng.Parts
|
||||||
ing.Location = i.Location
|
ing.Location = nIng.Location
|
||||||
ing.Quantity = qty
|
ing.Quantity = qty
|
||||||
ing.Notes = i.Notes
|
ing.Notes = nIng.Notes
|
||||||
r.Parts = append(r.Parts, ing)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user