"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/cents.py $
$Id: cents.py 29619 2007-03-15 18:44:42Z dbinger $
"""
from qp.lib.spec import either, require, specify, Specified

class Cents (Specified):

    cents_is = either(int, long)

    def __init__(self, value=0):
        specify(self, cents=value)

    def get_cents(self):
        return self.cents

    def __str__(self):
        return "$%.02f" % self.get_dollars()

    def get_dollars(self):
        return self.cents / 100.0

    def __add__(self, other):
        require(other, Cents)
        return Cents(self.cents + other.cents)

    def __sub__(self, other):
        require(other, Cents)
        return Cents(self.cents - other.cents)

    def __cmp__(self, other):
        require(other, Cents)
        return cmp(self.cents, other.cents)

