Class: Rotoworld::Scraper
- Inherits:
-
Object
- Object
- Rotoworld::Scraper
- Defined in:
- lib/Scraper.rb
Instance Attribute Summary collapse
-
#headline ⇒ Object
Returns the value of attribute headline.
-
#impact ⇒ Object
Returns the value of attribute impact.
-
#index ⇒ Object
Returns the value of attribute index.
-
#source ⇒ Object
Returns the value of attribute source.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#get_posts ⇒ Object
Scrapes Rotoworld NFL Players news feed to provide a list of posts with the attributes of title, headline, source, impact statement, and an index number to display with the post.
Instance Attribute Details
#headline ⇒ Object
Returns the value of attribute headline.
11 12 13 |
# File 'lib/Scraper.rb', line 11 def headline @headline end |
#impact ⇒ Object
Returns the value of attribute impact.
11 12 13 |
# File 'lib/Scraper.rb', line 11 def impact @impact end |
#index ⇒ Object
Returns the value of attribute index.
11 12 13 |
# File 'lib/Scraper.rb', line 11 def index @index end |
#source ⇒ Object
Returns the value of attribute source.
11 12 13 |
# File 'lib/Scraper.rb', line 11 def source @source end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/Scraper.rb', line 11 def title @title end |
Instance Method Details
#get_posts ⇒ Object
Scrapes Rotoworld NFL Players news feed to provide a list of posts with the attributes of title, headline, source, impact statement, and an index number to display with the post.
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 |
# File 'lib/Scraper.rb', line 17 def get_posts doc = Nokogiri::HTML(open("http://www.rotoworld.com/playernews/nfl/football-player-news/?ls=roto:nfl:gnav&rw=1")) player_set = doc.css("div.RW_pn div.pb") index = 1 player_set.each do |player| post = Rotoworld::Post.new post_title_info = player.css("div.headline div.player").text player_name = player.css("div.headline div.player a").first.text player_position_team = post_title_info.match(/- .+\s+-+\s+.+[str$]/) post.title = "#{player_name}#{player_position_team}" post.headline = player.css("div.report p").text post.impact = player.css("div.impact").first.text.strip if player.css("div.info div.source").text != "" post.source = player.css("div.info div.source a").attr("href").value else post.source = nil end post.index = index index +=1 end end |