src/methods/artoo.methods.scrape.js
function scrape(iterator, data, params, cb) {
    var $ = artoo.$,
        scraped = [],
        loneSelector = !!data.attr || !!data.method || data.scrape ||
                       typeof data === 'string' ||
                       typeof data === 'function';

    params = params || {};

    // Transforming to selector
    var $iterator;
    if (typeof iterator === 'function')
      $iterator = $(iterator($));
    else
      $iterator = $(iterator);

    // Iteration
    $iterator.each(function(i) {
      var item = {},
          p;

      // TODO: figure iteration scope elsewhere for scrape recursivity
      if (loneSelector)
        item = (typeof data === 'object' && 'scrape' in data) ?
          scrape(
            (data.sel ? $(this).find(data.sel) : $(this))
              .find(data.scrape.iterator),
            data.scrape.data,
            data.scrape.params
          ) :
          step(data, this);
      else
        for (p in data) {
          item[p] = (typeof data[p] === 'object' && 'scrape' in data[p]) ?
            scrape(
              (data[p].sel ? $(this).find(data[p].sel) : $(this))
                .find(data[p].scrape.iterator),
              data[p].scrape.data,
              data[p].scrape.params
            ) :
            step(data[p], this);
        }

      scraped.push(item);

      // Breaking if limit i attained
      return !params.limit || i < params.limit - 1;
    });

    scraped = params.one ? scraped[0] : scraped;

    // Triggering callback
    if (typeof cb === 'function')
      cb(scraped);

    // Returning data
    return scraped;
  }
function scrape(iterator, data, params, cb) {
    var $ = artoo.$,
        scraped = [],
        loneSelector = !!data.attr || !!data.method || data.scrape ||
                       typeof data === 'string' ||
                       typeof data === 'function';

    params = params || {};

    // Transforming to selector
    var $iterator;
    if (typeof iterator === 'function')
      $iterator = $(iterator($));
    else
      $iterator = $(iterator);

    // Iteration
    $iterator.each(function(i) {
      var item = {},
          p;

      // TODO: figure iteration scope elsewhere for scrape recursivity
      if (loneSelector)
        item = (typeof data === 'object' && 'scrape' in data) ?
          scrape(
            (data.sel ? $(this).find(data.sel) : $(this))
              .find(data.scrape.iterator),
            data.scrape.data,
            data.scrape.params
          ) :
          step(data, this);
      else
        for (p in data) {
          item[p] = (typeof data[p] === 'object' && 'scrape' in data[p]) ?
            scrape(
              (data[p].sel ? $(this).find(data[p].sel) : $(this))
                .find(data[p].scrape.iterator),
              data[p].scrape.data,
              data[p].scrape.params
            ) :
            step(data[p], this);
        }

      scraped.push(item);

      // Breaking if limit i attained
      return !params.limit || i < params.limit - 1;
    });

    scraped = params.one ? scraped[0] : scraped;

    // Triggering callback
    if (typeof cb === 'function')
      cb(scraped);

    // Returning data
    return scraped;
  }
function scrape ( iterator , data , params , cb ) { var $ = artoo . $ , scraped = [ ] , loneSelector = ! ! data . attr || ! ! data . method || data . scrape || typeof data === 'string' || typeof data === 'function' ; params = params || { } ; // Transforming to selector var $iterator ; if ( typeof iterator === 'function' ) $iterator = $ ( iterator ( $ ) ) ; else $iterator = $ ( iterator ) ; // Iteration $iterator . each ( function ( i ) { var item = { } , p ; // TODO: figure iteration scope elsewhere for scrape recursivity if ( loneSelector ) item = ( typeof data === 'object' && 'scrape' in data ) ? scrape ( ( data . sel ? $ ( this ) . find ( data . sel ) : $ ( this ) ) . find ( data . scrape . iterator ) , data . scrape . data , data . scrape . params ) : step ( data , this ) ; else for ( p in data ) { item [ p ] = ( typeof data [ p ] === 'object' && 'scrape' in data [ p ] ) ? scrape ( ( data [ p ] . sel ? $ ( this ) . find ( data [ p ] . sel ) : $ ( this ) ) . find ( data [ p ] . scrape . iterator ) , data [ p ] . scrape . data , data [ p ] . scrape . params ) : step ( data [ p ] , this ) ; } scraped . push ( item ) ; // Breaking if limit i attained return ! params . limit || i < params . limit - 1 ; } ) ; scraped = params . one ? scraped [ 0 ] : scraped ; // Triggering callback if ( typeof cb === 'function' ) cb ( scraped ) ; // Returning data return scraped ; }
Scraping function after polymorphism has been taken care of
Scraping function after polymorphism has been taken care of