Example #1
0
class GoonGroup(object):
    def __init__(self):
        self._goons = set()
        self._traits = TraitList()

    def add(self, goon):
        self._traits.reset()
        self._goons.add(goon)

    def remove(self, goon):
        self._traits.reset()
        self._goons.remove(goon)

    @property
    def traits(self):
        if len(self._traits) == 0:
            for goon in self._goons:
                for trait in goon.traits:
                    if trait not in self._traits:
                        self._traits.add(trait.trait, trait.value)

                    group_trait = self._traits.get(trait.trait)
                    group_trait += trait
        return self._traits

    def __iter__(self):
        return iter(self._goons)