src/conrad.js
function _getStats(v1, v2) {
    var a,
        k,
        i,
        l,
        stats,
        pattern,
        isPatternString;

    if (!arguments.length) {
      stats = [];

      for (k in _jobs)
        stats.push(_jobs[k]);

      for (k in _waitingJobs)
        stats.push(_waitingJobs[k]);

      for (k in _runningJobs)
        stats.push(_runningJobs[k]);

      stats = stats.concat(_doneJobs);
    }

    if (typeof v1 === 'string')
      switch (v1) {
        case 'waiting':
          stats = __objectValues(_waitingJobs);
          break;
        case 'running':
          stats = __objectValues(_runningJobs);
          break;
        case 'done':
          stats = _doneJobs;
          break;
        default:
          pattern = v1;
      }

    if (v1 instanceof RegExp)
      pattern = v1;

    if (!pattern && (typeof v2 === 'string' || v2 instanceof RegExp))
      pattern = v2;

    // Filter jobs if a pattern is given:
    if (pattern) {
      isPatternString = typeof pattern === 'string';

      if (stats instanceof Array) {
        a = stats;
      } else if (typeof stats === 'object') {
        a = [];

        for (k in stats)
          a = a.concat(stats[k]);
      } else {
        a = [];

        for (k in _jobs)
          a.push(_jobs[k]);

        for (k in _waitingJobs)
          a.push(_waitingJobs[k]);

        for (k in _runningJobs)
          a.push(_runningJobs[k]);

        a = a.concat(_doneJobs);
      }

      stats = [];
      for (i = 0, l = a.length; i < l; i++)
        if (isPatternString ? a[i].id === pattern : a[i].id.match(pattern))
          stats.push(a[i]);
    }

    return __clone(stats);
  }
function _getStats(v1, v2) {
    var a,
        k,
        i,
        l,
        stats,
        pattern,
        isPatternString;

    if (!arguments.length) {
      stats = [];

      for (k in _jobs)
        stats.push(_jobs[k]);

      for (k in _waitingJobs)
        stats.push(_waitingJobs[k]);

      for (k in _runningJobs)
        stats.push(_runningJobs[k]);

      stats = stats.concat(_doneJobs);
    }

    if (typeof v1 === 'string')
      switch (v1) {
        case 'waiting':
          stats = __objectValues(_waitingJobs);
          break;
        case 'running':
          stats = __objectValues(_runningJobs);
          break;
        case 'done':
          stats = _doneJobs;
          break;
        default:
          pattern = v1;
      }

    if (v1 instanceof RegExp)
      pattern = v1;

    if (!pattern && (typeof v2 === 'string' || v2 instanceof RegExp))
      pattern = v2;

    // Filter jobs if a pattern is given:
    if (pattern) {
      isPatternString = typeof pattern === 'string';

      if (stats instanceof Array) {
        a = stats;
      } else if (typeof stats === 'object') {
        a = [];

        for (k in stats)
          a = a.concat(stats[k]);
      } else {
        a = [];

        for (k in _jobs)
          a.push(_jobs[k]);

        for (k in _waitingJobs)
          a.push(_waitingJobs[k]);

        for (k in _runningJobs)
          a.push(_runningJobs[k]);

        a = a.concat(_doneJobs);
      }

      stats = [];
      for (i = 0, l = a.length; i < l; i++)
        if (isPatternString ? a[i].id === pattern : a[i].id.match(pattern))
          stats.push(a[i]);
    }

    return __clone(stats);
  }
function _getStats ( v1 , v2 ) { var a , k , i , l , stats , pattern , isPatternString ; if ( ! arguments . length ) { stats = [ ] ; for ( k in _jobs ) stats . push ( _jobs [ k ] ) ; for ( k in _waitingJobs ) stats . push ( _waitingJobs [ k ] ) ; for ( k in _runningJobs ) stats . push ( _runningJobs [ k ] ) ; stats = stats . concat ( _doneJobs ) ; } if ( typeof v1 === 'string' ) switch ( v1 ) { case 'waiting' : stats = __objectValues ( _waitingJobs ) ; break ; case 'running' : stats = __objectValues ( _runningJobs ) ; break ; case 'done' : stats = _doneJobs ; break ; default : pattern = v1 ; } if ( v1 instanceof RegExp ) pattern = v1 ; if ( ! pattern && ( typeof v2 === 'string' || v2 instanceof RegExp ) ) pattern = v2 ; // Filter jobs if a pattern is given: if ( pattern ) { isPatternString = typeof pattern === 'string' ; if ( stats instanceof Array ) { a = stats ; } else if ( typeof stats === 'object' ) { a = [ ] ; for ( k in stats ) a = a . concat ( stats [ k ] ) ; } else { a = [ ] ; for ( k in _jobs ) a . push ( _jobs [ k ] ) ; for ( k in _waitingJobs ) a . push ( _waitingJobs [ k ] ) ; for ( k in _runningJobs ) a . push ( _runningJobs [ k ] ) ; a = a . concat ( _doneJobs ) ; } stats = [ ] ; for ( i = 0 , l = a . length ; i < l ; i ++ ) if ( isPatternString ? a [ i ] . id === pattern : a [ i ] . id . match ( pattern ) ) stats . push ( a [ i ] ) ; } return __clone ( stats ) ; }
Returns a snapshot of every data about jobs that wait to be started, are
currently running or are done.

It is possible to get only running, waiting or done jobs by giving
"running", "waiting" or "done" as fist argument.

It is also possible to get every job with a specified id by giving it as
first argument. Also, using a RegExp instead of an id will return every
jobs whose ids match the RegExp. And these two last use cases work as well
by giving before "running", "waiting" or "done".

@return {Array} The array of the matching jobs.

Some call examples:
*******************
> conrad.getStats('running')
> conrad.getStats('waiting')
> conrad.getStats('done')
> conrad.getStats('myJob')
> conrad.getStats(/test/)
> conrad.getStats('running', 'myRunningJob')
> conrad.getStats('running', /test/)
Returns a snapshot of every data about jobs that wait to be started are currently running or are done .