Documentation ¶
Index ¶
Examples ¶
Constants ¶
const NoQty = 0
The value representing an unparsable Qty
e.g. {Qty = "A splash", QtyVal = cook.NoQty}
Variables ¶
This section is empty.
Functions ¶
func TryParseQty ¶
Attempt to parse a quantity fraction string into a float representation. Additionally, parses decimals/whole values. e.g. "1.5", "5" cook.NoQty is returned on failure
Types ¶
type Chunk ¶
type Chunk interface { ToString() string // contains filtered or unexported methods }
Chunks are the building blocks of recipe steps. They are a union of Text, Ingredient, Timer and Cookware.
type Component ¶
type Component struct { Name string `json:"name"` Qty string `json:"qty"` QtyVal float64 `json:"qtyVal"` Unit string `json:"unit"` }
Represents a generic `Component`, used in cooklang to define ingredients, cookware and timers.
type Ingredient ¶
type Ingredient Component
func (Ingredient) ToString ¶
func (x Ingredient) ToString() string
Converts an ingredient to a string, with its name followed by qty and units if they exist.
type Recipe ¶
type Recipe struct { Name string `json:"name"` Metadata map[string]string `json:"metadata"` Ingredients []Ingredient `json:"ingredients"` Cookware []Cookware `json:"cookware"` Timers []Timer `json:"timers"` Steps []Step `json:"steps"` }
Recipes consist primarily of Metadata and Steps. Steps are stored sequentially and offer a continuous construction of the parsed `.cook` file.
Additionally, the Ingredients, Cookware and Timer members provide a manifest for each of the respective item classes.
Recipes can be easily parsed from a string using the function `ParseRecipe`.
func ParseRecipe ¶
Parses a byte array containing a recipe following the cooklang specifications and returns as a `Recipe` struct
Example ¶
recipeText := `Preheat #deep fryer{} to 190°C. Slice @potatoes{3} into 1/4" strips. Optionally, blanch in boiling @water{2%cups}. Drop into deep fryer for ~{7%mins}. Remove from fryer and sprinkle @pink salt{} Enjoy with @ketchup, or mix in @mayonnaise{equal parts} for fancy sauce.` data := []byte(recipeText) recipe := ParseRecipe("Fries", &data) fmt.Println(recipe.Ingredients)
Output: [{potatoes 3 3 } {water 2 2 cups} {pink salt 0 } {ketchup 0 } {mayonnaise equal parts 0 }]
func ParseRecipeString ¶
Example ¶
recipeText := `Preheat #deep fryer{} to 190°C. Slice @potatoes{3} into 1/4" strips. Optionally, blanch in boiling @water{2%cups}. Drop into deep fryer for ~{7%mins}. Remove from fryer and sprinkle @pink salt{} Enjoy with @ketchup, or mix in @mayonnaise{equal parts} for fancy sauce.` recipe := ParseRecipeString("Fries", recipeText) fmt.Println(recipe.Ingredients)
Output: [{potatoes 3 3 } {water 2 2 cups} {pink salt 0 } {ketchup 0 } {mayonnaise equal parts 0 }]
type Step ¶
type Step []Chunk
A Step is one part of a recipe, consisting of a set of chunks which can be read in order to build a human readable recipe.
Ingredients, Cookware and Timer are kept as structs to allow for post processing (such as text formatting).
func (*Step) MarshalJSON ¶
Custom JSON encoding wraps each of `Step`'s chunk into a struct that stores the type to allow for unambiguous decoding.
e.g. an ingredient chunk will be wrapped as encoded as: `{'tag': 'ingredient', 'data': {...}}`
func (*Step) UnmarshalJSON ¶
Decodes the custom wrapped chunks created by the encoder back into an array of `Chunk`s.