Find a tournament bracket in a tweet (or any data object).
This is now part of the data repo.
For bracket.club, users enter by tweeting a link to their bracket. This module can parse a tweet and determine if it contains a valid bracket. It also has a lower level method find
that can be used to find a tweet in a more generic data object.
- It will check whether any links are from
options.domain
- If that fails, it will check whether any of the tags match a tag from
options.tags
If both of those fail, it will fire the callback with an error (unless forceMatch
contains either tags
or domain
). After that it will look for a bracket in:
- Any of the urls that match the domain
- Any of the tags
- Any chunks of text (split by spaces)
If any of these find a bracket, it will be validated the result will be passed to the callback. If no bracket is still found, any URLs will be followed using simple-realurl and checked again to see if they match the domain and contain a bracket.
Make a new bracket-finder
object with an options object (the year and sport options are required and passed directly to bracket-data
):
var BracketFinder = require('bracket-finder');
var finder = new BracketFinder({
year: '2013',
sport: 'ncaam',
domain: 'bracket.club',
tags: ['tybrtk']
});
finder.tweet(tweet, function (err, bracket) {
if (err) return; // No bracket found
// Do something with bracket
});
sport
: The sport you are validating. Seebracket-data
for more info.year
: The year you are validating. Seebracket-data
for more info.domain
: (String, default: '') The domain that a bracket tweet or data object might containtags
: (Array, default: []) An array of (hash)tags (but without the#
) that a bracket tweet or data object might containforceMatch
: (Array, default: ['tags']) Indicates which properties must be specified in the data. Can containtags
,domain
, both or neitherallowCrossDomain
: (Boolean, default: depends on environment) By default if you run this in a browser, cross domain urls will not be requested. If you would like to change this, set the option totrue
. When running in node, it defaults to true.
tweet(tweetObject, cb)
: tweetObject should in the format of a tweet from Twitter's APIfind(dataObject, cb)
: dataObject should have the following:
{
urls: ['https://bracket.club/X'],
tags: ['bracketclub']
text: 'This is the text!'
}