Module: Nhkanga
- Defined in:
- lib/nhkanga.rb,
lib/nhkanga/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .scrape_article(link) ⇒ Object
-
.scrape_feed_articles(feed_url, iter = 0) ⇒ Object
Scrapes articles from a Yahoo Japanese news RRS feed By default scrapes all articles Limit amount of articles scraped with iter parameter (Fixnum).
Class Method Details
.scrape_article(link) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nhkanga.rb', line 50 def self.scrape_article(link) puts "Scraping link: #{link.url}" scraper = YahooScraper.new(link) # puts "Scraping text" scraper.scrape_text # puts "Creating article." article = Article.new(link, scraper.text) return article end |
.scrape_feed_articles(feed_url, iter = 0) ⇒ Object
Scrapes articles from a Yahoo Japanese news RRS feed By default scrapes all articles Limit amount of articles scraped with iter parameter (Fixnum)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nhkanga.rb', line 15 def self.scrape_feed_articles(feed_url, iter = 0) feed = Feed.new(feed_url) puts "Created feed from: #{feed_url}" articles = [] if iter == 0 feed.links.each do |link| article = self.scrape_article(link) puts "Adding article to array." articles << article end elsif iter.is_a?(Fixnum) iter.times do |i| link = feed.links[i] article = self.scrape_article(link) puts "Adding article to array." articles << article end else puts "Invalid iter input - please enter :all or a Fixnum" return end return articles end |