Skip to content

Instantly share code, notes, and snippets.

@myndzi
Created September 26, 2014 21:40
Show Gist options
  • Save myndzi/4b654ba731a239d2ec66 to your computer and use it in GitHub Desktop.
Save myndzi/4b654ba731a239d2ec66 to your computer and use it in GitHub Desktop.
var foo = new Thing(),
bar = new Thing();
foo.process(function (stream) {
return {
date: stream.splice('<div class="date">', '</div>'),
city: stream.splice('<h3 class="city">', '</h3>'),
url: stream.splice('<div class="item">', '</div>')
.match(/<a href="(.*?)">(.*?)<\/a>/)
}
}).on('url', bar);
bar.process(function (stream) {
return {
data: stream.splice('<div class="content">', '</div>')
}
}).on('data', whatever)
{ date: '9-25-2014', city: 'seattle', url: 'http://foo.com/seattle/1', content: 'whatever 1' }
{ date: '9-25-2014', city: 'seattle', url: 'http://foo.com/seattle/2', content: 'whatever 2' }
// not: { date: '9-26-2014', city: 'seattle', url: 'http://foo.com/seattle/2', content: 'whatever 2' }
{ date: '9-26-2014', city: 'seattle', url: 'http://foo.com/seattle/3', content: 'whatever 3' }
{ date: '9-26-2014', city: 'seattle', url: 'http://foo.com/seattle/4', content: 'whatever 4' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment