Inital commit
This commit is contained in:
24
recipe/recipe.go
Normal file
24
recipe/recipe.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"autobrew/action"
|
||||
"autobrew/ingredient"
|
||||
)
|
||||
|
||||
type Recipe struct {
|
||||
Steps []Step
|
||||
Ingredients []ingredient.Ingredient
|
||||
}
|
||||
|
||||
func (r *Recipe) LoadIngredients() {
|
||||
for _, step := range r.Steps {
|
||||
if step.Action == action.Prepare {
|
||||
for _, i := range step.Ingredients {
|
||||
if i.IngredientType != ingredient.Base {
|
||||
r.Ingredients = append(r.Ingredients, i)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
31
recipe/step.go
Normal file
31
recipe/step.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"autobrew/action"
|
||||
"autobrew/ingredient"
|
||||
)
|
||||
|
||||
type Step struct {
|
||||
Ingredients []ingredient.Ingredient
|
||||
Action action.StepAction
|
||||
Turns int
|
||||
}
|
||||
|
||||
func (f *Step) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
var t struct {
|
||||
Ingredients []ingredient.Ingredient `yaml:"ingredients"`
|
||||
Action action.StepAction `yaml:"action"`
|
||||
Turns int `yaml:"turns"`
|
||||
}
|
||||
|
||||
err := unmarshal(&t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.Action = t.Action
|
||||
f.Ingredients = t.Ingredients
|
||||
f.Turns = t.Turns
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user