Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AmountToString ¶
func SanitizeLine ¶
SanitizeLine removes parentheses, trims the line, converts to lower case, replaces fractions with unicode and then does special conversion for ingredients (like eggs).
Types ¶
type Ingredient ¶
type Ingredient struct { Name string `json:"name,omitempty"` Comment string `json:"comment,omitempty"` Measure Measure `json:"measure,omitempty"` Line string `json:"line,omitempty"` }
Ingredient is the basic struct for ingredients
func IngredientsFromURL ¶ added in v1.0.2
func IngredientsFromURL(url string) (ingredients []Ingredient, err error)
type IngredientList ¶
type IngredientList struct {
Ingredients []Ingredient `json:"ingredients"`
}
IngredientList is a list of ingredients
func ParseTextIngredients ¶
func ParseTextIngredients(text string) (ingredientList IngredientList, err error)
ParseTextIngredients parses a list of ingredients and returns an ingredient list back
func (IngredientList) String ¶
func (il IngredientList) String() string
type LineInfo ¶
type LineInfo struct { LineOriginal string Line string `json:",omitempty"` IngredientsInString []WordPosition `json:",omitempty"` AmountInString []WordPosition `json:",omitempty"` MeasureInString []WordPosition `json:",omitempty"` Ingredient Ingredient `json:",omitempty"` }
LineInfo has all the information for the parsing of a given line
type Measure ¶
type Measure struct { Amount float64 `json:"amount"` Name string `json:"name"` Cups float64 `json:"cups"` Weight float64 `json:"weight,omitempty"` }
Measure includes the amount, name and the cups for conversions
type Recipe ¶
type Recipe struct { FileName string `json:"filename"` FileContent string `json:"file_content"` Lines []LineInfo `json:"lines"` Ingredients []Ingredient `json:"ingredients"` }
Recipe contains the info for the file and the lines
func NewFromFile ¶
NewFromFile generates a new parser from a HTML file
func NewFromHTML ¶ added in v1.1.0
NewFromHTML generates a new parser from a HTML text
func NewFromString ¶
NewFromString generates a new parser from a HTML string
func NewFromURL ¶
NewFromURL generates a new parser from a url
func (*Recipe) ConvertIngredients ¶
func (*Recipe) IngredientList ¶
func (r *Recipe) IngredientList() (ingredientList IngredientList)
IngredientList will return a string containing the ingredient list
type WordPosition ¶
WordPosition shows a word and its position Note: the position is memory-dependent as it will be the position after the last deleted word
func GetIngredientsInString ¶
func GetIngredientsInString(s string) (wordPositions []WordPosition)
GetIngredientsInString returns the word positions of the ingredients
func GetMeasuresInString ¶
func GetMeasuresInString(s string) (wordPositions []WordPosition)
GetMeasuresInString returns the word positions of the measures in a ingredient string
func GetNumbersInString ¶
func GetNumbersInString(s string) (wordPositions []WordPosition)
GetNumbersInString returns the word positions of the numbers in the ingredient string