Base object
The BaseObj Class
The BaseObj class serves as the base for these objects:
IngredientTimingCookware
and defines certain methods, attributes, and properties that are common to all. Each base object must define the following:
prefix- This is the character, defined in the Cooklang specification, that denotes whether the text following is an ingredient (@), timing (~), or cookware (#).supports_notes- This is a boolean value indicating whether the defined object allows for notes per the Cooklang specification. Currently onlytimingdoes not support notes.
Attributes, properties, and methods
The BaseObj class contains the following methods:
BaseObj(
raw: str,
name: str,
*,
quantity: str = None,
notes: str = None,
):
"""
Constructor for the BaseObj class
:param raw: The raw string the ingredient came from
:param name: The name of the ingredient
:param quantity: The quantity as described in the raw string
:param notes: Notes from the raw string
"""
Parameters for the BaseObj method:
raw- the raw string that was used to create theBaseObj. If theBaseObjis being created directly this can be''with no ill effects.name- the name of the objectquantity- the quantity required as a string in the format<amount>%<unit>. Optional.notes- string defining preparation notes. Optional.
@classmethod
factory(raw)
The factory method for BaseObj will parse the raw string provided and create a new
BaseObj
# In this example we are using the factory to create an Ingredient.
Ingredient.factory('@cheddar cheese{1%cup}(shredded)')
Ingredient(raw='@cheddar cheese{1%cup}(shredded)', name='cheddar cheese', quantity='1%cup', notes='shredded')
The BaseObj class contains the following attributes:
name- the name of the objectnotes- preparation notesraw- the raw string used to create the ingredient. (Note that theBaseObjdoesn't actually parse the string unless created with thefactorymethod. The raw string may or may not be passed by the instantiating code.)
The BaseObj class contains the following properties:
quantity- TheQuantityof the ingredient. If theIngredientdoes not have aQuantitythis will be''.long_str- This returns theBaseObjas a string in the format<quantity> <name> (<notes>). This is in contrast tostr(BaseObj)which returns<name> (<quantity>).