Please note: read the guideline before starting.
You work at the In-N-Out and make delicious burgers.
Create the BurgerRecipe
class. Its __init__
method should accept and save the number of ingredients needed to make a burger, such as cheese, tomatoes, cutlets, eggs, buns, and sauce.
cheese_burger = Burger(buns=2, cheese=2, tomatoes=1, cutlets=1, eggs=1, sauce="ketchup")
You can make burgers with a different number of ingredients and different sauces, for example:
buns
— can range from2
to3
;cheese
— can range from0
to2
;tomatoes
— can range from0
to3
;cutlets
— can range from1
to3
;eggs
— can range from0
to2
;sauce
— can beketchup
,mayo
, orburger
.
So, it would be convenient to use descriptors to ensure that the number of ingredients is int
in a range mentioned above
and the sauce is one of ketchup
, mayo
, or burger
.
The main task is to create the BurgerRecipe
class, and for convenience, you should consider the descriptors.
Implement the Validator
class that will have such methods:
- the
__set_name__
method, which accepts the name of the attribute, adds_
to its beginning, and stores it in theprotected_name
attribute; - the
__get__
method that returns the attribute value; - the
__set__
method, which sets the attribute value (note that there should be no validation implemented, you should only call it there); - the
validate
abstract method, which accepts thevalue
.
Also, you need to implement the Number
class, which is the Validator
child class. It should have:
- the
__init__
method, which accepts and stores themin_value
and themax_value
; - the
validate
method, which checks the value type, and if the type is incorrect, it must raise theTypeError
exception with theQuantity should be integer.
message. Then it should check whether the value is withinmin_value
andmax_value
. If it’s not, it should raise theValueError
with theQuantity should not be less than {self.min_value} and greater than {self.max_value}.
message.
Last but not least, you need to implement the OneOf
validator, which is the child class of the Validator
class. It allows to choose one of the provided values and should have:
- the
__init__
method, which accepts and storesoptions
; - the
validate
method, which accepts thevalue
and checks if it’s one of the provided options and, if not — raises theValueError
with theExpected {value} to be one of {self.options}.
message.
burger = BurgerRecipe(buns="1", cheese="1", tomatoes="1", cutlets="1", eggs="1", sauce="mayo")
# TypeError: Quantity should be integer.
burger = BurgerRecipe(buns=1, cheese=10, tomatoes=1, cutlets=1, eggs=1, sauce="mayo")
# ValueError: Quantity should not be less than 2 and greater than 3.
burger = BurgerRecipe(buns=2, cheese=1, tomatoes=1, cutlets=1, eggs=1, sauce="mustard")
# ValueError: Expected mustard to be one of ('ketchup', 'mayo', 'burger').
burger = BurgerRecipe(buns=2, cheese=1, tomatoes=1, cutlets=1, eggs=1, sauce="ketchup")
# burger will be created
Please note: descriptors should be created as class attributes.