Class: MlbHeadlines::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/mlb_headlines/scraper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#articleObject

Returns the value of attribute article.



3
4
5
# File 'lib/mlb_headlines/scraper.rb', line 3

def article
  @article
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/mlb_headlines/scraper.rb', line 3

def title
  @title
end

Class Method Details

.scrapeObject



6
7
8
9
10
11
12
13
# File 'lib/mlb_headlines/scraper.rb', line 6

def self.scrape
  @doc = Nokogiri::HTML(open('http://www.cbssports.com/fantasy/baseball/players/news/all/both/'))
  @doc.css("ul#playerNewsContent li").map do |headline|
    title = headline.css("h4").text
    article = headline.css(".latest-updates p").map(&:text).join(" ")
    MlbHeadlines::Headline.new(title, article)
  end
end