Class: IGNReviews::Scraper
- Inherits:
-
Object
- Object
- IGNReviews::Scraper
- Defined in:
- lib/ign_reviews/scraper.rb
Overview
this will collect game details into hashes to create game objects from
Class Method Summary collapse
- .scrape_coming_soon ⇒ Object
- .scrape_description(url) ⇒ Object
- .scrape_editors_choice ⇒ Object
- .scrape_front_page ⇒ Object
Class Method Details
.scrape_coming_soon ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ign_reviews/scraper.rb', line 49 def self.scrape_coming_soon scraped_games = [] doc = Nokogiri::HTML(open("http://www.ign.com/reviews/games")) games = doc.css("div.column-game") games.each do |game| scraped_game = {} scraped_game[:name] = game.css("a.game-title").text.strip scraped_game[:platform] = game.css("span.game-platform").text scraped_game[:release_date] = game.css("div.date").text scraped_game[:url] = game.css("a")[0]["href"] scraped_game[:description] = scrape_description(game.css("a")[0]["href"]) scraped_games << scraped_game end scraped_games end |
.scrape_description(url) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/ign_reviews/scraper.rb', line 69 def self.scrape_description(url) doc = Nokogiri::HTML(open("#{url}")) description = doc.css("div.description").text.strip description end |
.scrape_editors_choice ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ign_reviews/scraper.rb', line 27 def self.scrape_editors_choice scraped_games = [] doc = Nokogiri::HTML(open("http://www.ign.com/editors-choice/games")) games = doc.css("div.gameList-game") games.each do |game| scraped_game = {} scraped_game[:name] = game.css("div.game-title a").text.strip scraped_game[:platform] = game.css("span.game-platform").text scraped_game[:genre] = game.css("span.game-genre").text.strip scraped_game[:rating] = game.css("span.scoreBox-score").text scraped_game[:release_date] = game.css("div.grid_3 div")[0].text scraped_game[:url] = game.css("li a")[0]["href"] scraped_game[:description] = game.css("p.game-details").text.split(/\s+- /).delete_if{|space|space == ""}[1] scraped_games << scraped_game end scraped_games end |
.scrape_front_page ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ign_reviews/scraper.rb', line 5 def self.scrape_front_page scraped_games = [] doc = Nokogiri::HTML(open("http://www.ign.com/reviews/games")) games = doc.css("div.itemList-item") games.each do |game| scraped_game = {} scraped_game[:name] = game.css("div.item-title a").text.strip scraped_game[:platform] = game.css("span.item-platform").text scraped_game[:genre] = game.css("span.item-genre").text.strip scraped_game[:rating] = game.css("span.scoreBox-score").text scraped_game[:release_date] = game.css("div.grid_3 div")[0].text scraped_game[:url] = game.css("li a")[0]["href"] scraped_game[:description] = game.css("p.item-details").text.split(/\s+- /).delete_if{|space|space == ""}[1] scraped_games << scraped_game end scraped_games end |