 
   isNegative: ->
     @cents < 0
+
+  equals: (other) ->
+    @cents == other.cents
 
   currencySymbol: ->
     '$' #TODO: implement proper currency

    @cents && (@cents / Math.abs(@cents))

  absoluteFormat: ->
    Math.abs(@cents/100.0).toFixed(2)

  isZero: ->
    @cents == 0

class Money
  constructor: (num) ->
    @cents = @getCents(num)

  getCents: (num) ->
    return 0 if num is null or num is 'undefined'
    return num if typeof num is 'number'
    return @buildFromString num if typeof num is 'string'
    console.warn "Please use a number when creating a Money object not a #{typeof num}. Called from #{arguments.callee.caller.toString()} with ", num
    0

  buildFromString: (num) ->
    # remove everything (comma, $, etc.) except the number and decimal in between
    # - decimal optional, no decimal = dollars
    num = num.replace(/,/g,'').match(/[0-9]+.?[0-9]*/, '')
    return 0 unless num? # if num is other string
    nums = num[0].split('.')
    dollars = parseInt(nums[0])
    cents = if nums[1]? then parseInt(nums[1]) else 0
    dollars * 100 + cents

  dollars: ->
    @cents / 100.0

  format: ->
    @dollars().toFixed(2)

  signClass: ->
    if @sign() == 1 then 'positive' else if @sign() == -1 then 'negative' else 'zero'
