Class: InternetWisdom::SiteManager
- Inherits:
-
Object
- Object
- InternetWisdom::SiteManager
- Defined in:
- lib/internet_wisdom/site_manager.rb
Instance Attribute Summary collapse
-
#sites ⇒ Object
Returns the value of attribute sites.
Class Method Summary collapse
- .scrape_brainy_quote_funny ⇒ Object
- .scrape_brainy_quote_inspirational ⇒ Object
-
.scrape_funtweets ⇒ Object
SITES:.
Instance Method Summary collapse
- #debug_scrape ⇒ Object
-
#initialize ⇒ SiteManager
constructor
A new instance of SiteManager.
Constructor Details
#initialize ⇒ SiteManager
Returns a new instance of SiteManager.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/internet_wisdom/site_manager.rb', line 5 def initialize # uncomment debug_scrape to use Nokogiri in development #debug_scrape # put all your sites and custom scraping here @sites = [ self.class.scrape_funtweets, self.class.scrape_brainy_quote_funny, self.class.scrape_brainy_quote_inspirational ] end |
Instance Attribute Details
#sites ⇒ Object
Returns the value of attribute sites.
3 4 5 |
# File 'lib/internet_wisdom/site_manager.rb', line 3 def sites @sites end |
Class Method Details
.scrape_brainy_quote_funny ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/internet_wisdom/site_manager.rb', line 43 def self.scrape_brainy_quote_funny brainy = InternetWisdom::Site.new("BrainyQuotes.com - Funny", true) brainy.refresh_method = Proc.new do |site| site.page_index = (1..39).to_a.sample doc = Nokogiri::HTML(open("http://www.brainyquote.com/quotes/topics/topic_funny#{site.page_index}.html")) site.posts = doc.search(".masonryitem").collect do |quote| h = { :author => quote.search("div.bq-aut a").text, :text => quote.search("span.bqQuoteLink a").text, :link => "http://www.brainyquote.com#{quote.search("div.bq-aut a").attribute("href").value}" } InternetWisdom::Post.new(h) end end brainy.refresh! end |
.scrape_brainy_quote_inspirational ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/internet_wisdom/site_manager.rb', line 60 def self.scrape_brainy_quote_inspirational brainy = InternetWisdom::Site.new("BrainyQuotes.com - Inspirational", true) brainy.refresh_method = Proc.new do |site| site.page_index = (1..15).to_a.sample doc = Nokogiri::HTML(open("http://www.brainyquote.com/quotes/topics/topic_inspirational#{site.page_index}.html")) site.posts = doc.search(".masonryitem").collect do |quote| h = { :author => quote.search("div.bq-aut a").text, :text => quote.search("span.bqQuoteLink a").text, :link => "http://www.brainyquote.com#{quote.search("div.bq-aut a").attribute("href").value}" } InternetWisdom::Post.new(h) end end brainy.refresh! end |
.scrape_funtweets ⇒ Object
SITES:
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/internet_wisdom/site_manager.rb', line 26 def self.scrape_funtweets funtweets = InternetWisdom::Site.new("FunTweets.com", true) funtweets.refresh_method = Proc.new do |site| doc = Nokogiri::HTML(open("http://funtweets.com/random")) site.posts = doc.search(".tweet").collect do |tweet| arr = tweet.search(".tweet-text").text.delete("\r\t").split("\n") h = { :author => arr[1].strip, :text => arr[2].strip, :link => "https://twitter.com/#{arr[1].strip}" } InternetWisdom::Post.new(h) end end funtweets.refresh! end |
Instance Method Details
#debug_scrape ⇒ Object
17 18 19 20 21 22 |
# File 'lib/internet_wisdom/site_manager.rb', line 17 def debug_scrape puts "DEBUG MODE: Enter a url you wish to scrape" url = gets.strip doc = Nokogiri::HTML(open(url)) binding.pry end |