Giter Site home page Giter Site logo

py-burger-recipe's Introduction

Burger Recipe

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 from 2 to 3;
  • cheese — can range from 0 to 2;
  • tomatoes — can range from 0 to 3;
  • cutlets — can range from 1 to 3;
  • eggs — can range from 0 to 2;
  • sauce — can be ketchup, mayo, or burger.

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 the protected_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 the value.

Also, you need to implement the Number class, which is the Validator child class. It should have:

  • the __init__ method, which accepts and stores the min_value and the max_value;
  • the validate method, which checks the value type, and if the type is incorrect, it must raise the TypeError exception with the Quantity should be integer. message. Then it should check whether the value is within min_value and max_value. If it’s not, it should raise the ValueError with the Quantity 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 stores options;
  • the validate method, which accepts the value and checks if it’s one of the provided options and, if not — raises the ValueError with the Expected {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.

py-burger-recipe's People

Contributors

danylott avatar dmytrosvirsa avatar masterpieceelbow avatar nattalli avatar y-havryliv avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.