bracket-finder
Find a tournament bracket in a tweet (or any data object).
Why is this useful?
For tweetyourbracket.com, 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.
How does it determine if a bracket is found?
- 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.
API / Usage
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 = ;var finder = year: '2013' sport: 'ncaam' domain: 'tweetyourbracket.com' tags: 'tybrtk';finder;
options
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.
methods
tweet(tweetObject, cb)
: tweetObject should in the format of a tweet from Twitter's APIfind(dataObject, cb)
: dataObject should have the following:
urls: 'http://tweetyourbracket.com/X' tags: 'tybrkt' text: 'This is the text!'