Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

82 lines (51 sloc) 2.355 kb

Tweet About Gem

Takes a twitter username and returns a list of words. Can also return a Hash with the count for each word. Options to not include retweets, to set the number of tweets to be processed, and to return all words, without removing the useless ones. See Options Hash.

The words are are ordered list of the most frequently tweeted words.

  • The casing of words doesn't matter (the = The = THE). Output is downcased.
  • URLs are removed.

Installation

gem install tweetabout

Gemfile

gem 'tweetabout'

Dependencies

httparty

Useage

Takes a single string, and an optional options hash

Returns

#instantiate and call the sort_words method
@tweetwords = TweetAbout::TweetWords.new("jack").sort_words

#now you have two attributes #stauts and #words
@tweetwords.status = :ok
can also be: :invalid_username, :no_tweets, or :error

#default returns an array of words, sorted from most to least tweeted.
@tweetwords.words = [frisbee, golf, ...]
#instantiate, call the sort_words method, and pass :with_count => true
@tweetwords = TweetAbout::TweetWords.new("jack").sort_words(:with_count => true)

#will now return a Hash with counts for each word
@tweetwords.words = {"fisbee" => 5, "golf"   => 3, ...} }

Options Hash:

#TweetAbout::TweetWords.new("@username").sort_words(:options => {})
tweets:      n      (default 200)   #the number of tweets to process
include_rts: t/f    (default true)  #include re-tweets by default
with_count:  t/f    (default false) #if true, returns a Hash in the form of {word: n}, otherwise an Array of words is returned
all_words:   t/f    (default false) #see `Junk Words`.  If set to true, no words are left out

Examples

#returns an Array of words sorted by most frequent.
TweetAbout::TweetWords.new("jack").sort_words

#returns a Hash of words with each count sorted by most frequent.
TweetAbout::TweetWords.new("jack").sort(with_count: true)

#returns an Array of words sorted by most frequent for last 1,000 tweets
TweetAbout::TweetWords.new("jack").sort(tweets: 1000)

Junk Words

These words are removed. If you don't want them removed, pass the option :all_words => true

articles: "the", "a", "an" pronouns: "he", "him", "her", "she", "i", "you", "they", "them", "it" other_junk: "for", "from", "not", "but"

Jump to Line
Something went wrong with that request. Please try again.