class LastTweet::TwitterAccount
Attributes
bio[RW]
handle[RW]
name[RW]
tweets[RW]
url[RW]
Public Class Methods
all()
click to toggle source
# File lib/last_tweet/twitter_account.rb, line 5 def self.all @@all end
create_from_handle(t_handle)
click to toggle source
# File lib/last_tweet/twitter_account.rb, line 9 def self.create_from_handle(t_handle) unless all.any?{|acct| acct.handle == t_handle} account = new account.handle = t_handle account.url = "https://twitter.com/" + t_handle[1..-1] name_qry = ["div.ProfileHeaderCard h1.ProfileHeaderCard-name a.ProfileHeaderCard-nameLink", "text", "method"] bio_qry = ["div.ProfileHeaderCard p.ProfileHeaderCard-bio", "text", "method"] what_to_scrape = {name: name_qry, bio: bio_qry} twitter_hash = LastTweet::Scraper.scrape(account.url, what_to_scrape) account.name = twitter_hash[:name] account.bio = twitter_hash[:bio] account.tweets = [] @@all << account end all.detect{|acct| acct.handle == t_handle} end
most_popular(n=5)
click to toggle source
# File lib/last_tweet/twitter_account.rb, line 29 def self.most_popular(n=5) url = "http://friendorfollow.com/twitter/most-followers/" n.times.collect do |i| handle_qry = ["div\#list-container ul.view-list li.row-#{i+1} div.text-holder a", "text", "method"] what_to_scrape = {handle: handle_qry} twitter_hash = LastTweet::Scraper.scrape(url, what_to_scrape) create_from_handle(twitter_hash[:handle]) end end
Public Instance Methods
remove()
click to toggle source
# File lib/last_tweet/twitter_account.rb, line 39 def remove @@all.delete(self) end