<commit_before># -*- coding: utf-8 -*-

"""
byceps.blueprints.shop.models.cart
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2015 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from ....util.instances import ReprBuilder


class Cart(object):
    """A shopping cart."""

    def __init__(self):
        self._items = []

    def add_item(self, article, quantity):
        item = CartItem(article, quantity)
        self._items.append(item)

    def get_items(self):
        return self._items

    def is_empty(self):
        return not self._items

    def __repr__(self):
        return ReprBuilder(self) \
            .add_custom('{:d} items'.format(len(self._items))) \
            .build()


class CartItem(object):
    """An article with a quantity."""

    def __init__(self, article, quantity):
        if quantity < 1:
            raise ValueError('Quantity must be a positive number.')

        self.article = article
        self.quantity = quantity

    def __repr__(self):
        return ReprBuilder(self) \
            .add_with_lookup('item_number') \
            .add_with_lookup('quantity') \
            .build()
<commit_msg>Fixed text representation of `CartItem` instances.<commit_after># -*- coding: utf-8 -*-

"""
byceps.blueprints.shop.models.cart
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2015 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from ....util.instances import ReprBuilder


class Cart(object):
    """A shopping cart."""

    def __init__(self):
        self._items = []

    def add_item(self, article, quantity):
        item = CartItem(article, quantity)
        self._items.append(item)

    def get_items(self):
        return self._items

    def is_empty(self):
        return not self._items

    def __repr__(self):
        return ReprBuilder(self) \
            .add_custom('{:d} items'.format(len(self._items))) \
            .build()


class CartItem(object):
    """An article with a quantity."""

    def __init__(self, article, quantity):
        if quantity < 1:
            raise ValueError('Quantity must be a positive number.')

        self.article = article
        self.quantity = quantity

    def __repr__(self):
        return ReprBuilder(self) \
            .add('article', self.article.item_number) \
            .add_with_lookup('quantity') \
            .build()

{'fraction_non_alphanumeric': 0.15339233038348082, 'fraction_numerical': 0.008428150021070375, 'mean_word_length': 2.4505813953488373, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2641249', 'n_tokens_mistral': 715, 'n_tokens_neox': 666, 'n_words': 170}