{ "info": { "author": "Victor Oliveira da Silva", "author_email": "victor_o_silva@hotmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.7" ], "description": "========================\nsimple_specification\n========================\n\n.. image:: https://travis-ci.org/victor-o-silva/simple-specification.svg?branch=master\n :target: https://travis-ci.org/victor-o-silva/simple-specification\n :alt: Build Status\n\n.. image:: https://coveralls.io/repos/victor-o-silva/simple-specification/badge.svg?branch=master\n :target: https://coveralls.io/r/victor-o-silva/simple-specification?branch=master\n :alt: Code Coverage\n\n.. image:: https://badge.fury.io/py/simple-specification.svg\n :target: https://badge.fury.io/py/simple-specification\n\n\nA simple pythonic implementation of the `Specification Pattern `_ for Python 3.7 or higher.\n\nInstallation\n############\n\n.. code-block:: sh\n\n pip install simple-specification\n\nExamples\n##########\n\nCreating specification classes to check integer numbers\n*******************************************************\n\n.. code-block:: python\n\n from simple_specification import Specification\n\n\n # hardcoded specification\n class Odd(Specification):\n def is_satisfied_by(self, candidate: int) -> bool:\n return candidate % 2 != 0\n\n\n # parametrized specification\n class DivisibleBy(Specification):\n def __init__(self, number: int):\n self.number = number\n\n def is_satisfied_by(self, candidate: int) -> bool:\n return candidate % self.number == 0\n\nInstantiating the specifications\n********************************\n\n.. code-block:: python\n\n >>> odd = Odd()\n >>> even = ~odd\n >>> div3 = DivisibleBy(3)\n >>> div5 = DivisibleBy(5)\n\nUsing specifications - method ``is_satisfied_by(candidate)``\n************************************************************\n\n.. code-block:: python\n\n >>> odd.is_satisfied_by(1)\n True\n >>> odd.is_satisfied_by(2)\n False\n >>> even.is_satisfied_by(3)\n False\n >>> even.is_satisfied_by(4)\n True\n >>> div3.is_satisfied_by(9)\n True\n >>> div5.is_satisfied_by(12)\n False\n\nComposing specifications - operators ``&`` and ``|``\n****************************************************\n\n.. code-block:: python\n\n >>> # AND\n >>> (even & div3).is_satisfied_by(6)\n True\n >>> (even & div3).is_satisfied_by(9)\n False\n >>> (even & div3 & div5).is_satisfied_by(30)\n True\n >>> (even & div3 & div5).is_satisfied_by(36)\n False\n >>>\n >>> # OR\n >>> (even | div3).is_satisfied_by(10)\n True\n >>> (even | div3).is_satisfied_by(15)\n True\n >>> (even | div3).is_satisfied_by(5)\n False\n\nNegating specifications - operator ``~``\n****************************************\n\n.. warning:: Always surround the negation with parenthesis\n\n.. code-block:: python\n\n >>> (~odd).is_satisfied_by(2)\n True\n >>> (~div5).is_satisfied_by(25)\n False\n >>> (~div5).is_satisfied_by(11)\n True\n >>> (~(odd | div5)).is_satisfied_by(6)\n True\n >>> (~(odd | div5)).is_satisfied_by(7)\n False\n\nComposing a list of specifications with ``&`` - class method ``Specification.all(specs)``\n********************************************************************************************\n\n.. code-block:: python\n\n >>> all_spec = Specification.all([~even, div3, div5])\n >>> all_spec.is_satisfied_by(15)\n True\n >>> all_spec.is_satisfied_by(30)\n False\n >>> all_spec.is_satisfied_by(25)\n False\n >>> all_spec.is_satisfied_by(6)\n False\n\nComposing a list of specifications with ``|`` - class method ``Specification.any(specs)``\n**********************************************************************************************\n\n.. code-block:: python\n\n >>> div15 = DivisibleBy(3) & DivisibleBy(5)\n >>> any_spec = Specification.any([div15, even])\n >>> any_spec.is_satisfied_by(2)\n True\n >>> any_spec.is_satisfied_by(15)\n True\n >>> any_spec.is_satisfied_by(30)\n True\n >>> any_spec.is_satisfied_by(3)\n False\n >>> any_spec.is_satisfied_by(5)\n False\n\n\n", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "https://github.com/victor-o-silva/simple-specification/tarball/0.3", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/victor-o-silva/simple-specification", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "simple-specification", "package_url": "https://pypi.org/project/simple-specification/", "platform": "", "project_url": "https://pypi.org/project/simple-specification/", "project_urls": { "Download": "https://github.com/victor-o-silva/simple-specification/tarball/0.3", "Homepage": "https://github.com/victor-o-silva/simple-specification" }, "release_url": "https://pypi.org/project/simple-specification/0.3/", "requires_dist": null, "requires_python": "", "summary": "A simple pythonic implementation of the Specification Pattern for Python 3.7 or higher.", "version": "0.3" }, "last_serial": 5904350, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "91a45a3ab5e16070aa0a2cd0e7852a9d", "sha256": "2a1d72f1d5a4995ee6d6a79c29172e8e29c4f35ade0da25022b237425b3a3a67" }, "downloads": -1, "filename": "simple_specification-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "91a45a3ab5e16070aa0a2cd0e7852a9d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3517, "upload_time": "2019-09-30T01:30:39", "url": "https://files.pythonhosted.org/packages/61/76/67a449e53b287de5b1cf47705c28432bf1ce8505da8d0cf4c7c1f663034d/simple_specification-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "65e7b869ef5dd462fdf6d07bd50a5f9b", "sha256": "549f67cd6593329d361a468d72ca745a6b9035622f049402157f33436606c426" }, "downloads": -1, "filename": "simple-specification-0.1.tar.gz", "has_sig": false, "md5_digest": "65e7b869ef5dd462fdf6d07bd50a5f9b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2518, "upload_time": "2019-09-30T01:30:41", "url": "https://files.pythonhosted.org/packages/88/94/db5649e08e07a15c2fe629a9e36f77b89d161f2218f30df7fa252ce14783/simple-specification-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "85d4d0dfba00560c3b422d7529198147", "sha256": "8d87efaf184b189bdf3e112232d711028ecb0cfda608b552e4375f466d8f1d84" }, "downloads": -1, "filename": "simple_specification-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "85d4d0dfba00560c3b422d7529198147", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3555, "upload_time": "2019-09-30T01:44:08", "url": "https://files.pythonhosted.org/packages/24/3f/4a46945b80ba800b79cb626ebf50f968eeecc9cbaf18ac78e8f21593422c/simple_specification-0.2-py3-none-any.whl" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "d0de361c12fb53b6f215b1749720855c", "sha256": "e3e9e098bfcd78bcac75c2fcec906afd0f01b60d2b256edb641885a8125900fd" }, "downloads": -1, "filename": "simple_specification-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "d0de361c12fb53b6f215b1749720855c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3555, "upload_time": "2019-09-30T01:46:32", "url": "https://files.pythonhosted.org/packages/e1/9a/8908b5cc0ecf17466526eb3322fb2c42cceee92c798ffbadc0714c9cfd7a/simple_specification-0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c2fbdd54e9799ffeaf44358534edbd98", "sha256": "1d75783c12479ac1d40072b9976fdd73c26eb4918ded81da2ec03991d0846dc6" }, "downloads": -1, "filename": "simple-specification-0.3.tar.gz", "has_sig": false, "md5_digest": "c2fbdd54e9799ffeaf44358534edbd98", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2609, "upload_time": "2019-09-30T01:46:34", "url": "https://files.pythonhosted.org/packages/40/a7/aa5aa306e56fbf4260f4e66bd01b59a1a2023f2d7b1cc9115d4667a950dd/simple-specification-0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d0de361c12fb53b6f215b1749720855c", "sha256": "e3e9e098bfcd78bcac75c2fcec906afd0f01b60d2b256edb641885a8125900fd" }, "downloads": -1, "filename": "simple_specification-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "d0de361c12fb53b6f215b1749720855c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3555, "upload_time": "2019-09-30T01:46:32", "url": "https://files.pythonhosted.org/packages/e1/9a/8908b5cc0ecf17466526eb3322fb2c42cceee92c798ffbadc0714c9cfd7a/simple_specification-0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c2fbdd54e9799ffeaf44358534edbd98", "sha256": "1d75783c12479ac1d40072b9976fdd73c26eb4918ded81da2ec03991d0846dc6" }, "downloads": -1, "filename": "simple-specification-0.3.tar.gz", "has_sig": false, "md5_digest": "c2fbdd54e9799ffeaf44358534edbd98", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2609, "upload_time": "2019-09-30T01:46:34", "url": "https://files.pythonhosted.org/packages/40/a7/aa5aa306e56fbf4260f4e66bd01b59a1a2023f2d7b1cc9115d4667a950dd/simple-specification-0.3.tar.gz" } ] }