Class: NewGameScores::CollectionScraper
- Inherits:
-
Object
- Object
- NewGameScores::CollectionScraper
- Defined in:
- lib/new_game_scores/collection_scraper.rb
Constant Summary collapse
- @@collection =
[]
Instance Attribute Summary collapse
-
#game_url ⇒ Object
Returns the value of attribute game_url.
-
#metascore ⇒ Object
Returns the value of attribute metascore.
-
#name ⇒ Object
Returns the value of attribute name.
-
#score ⇒ Object
Returns the value of attribute score.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
-
#userscore ⇒ Object
Returns the value of attribute userscore.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
- #display_list ⇒ Object
-
#initialize(url = nil, score = nil) ⇒ CollectionScraper
constructor
A new instance of CollectionScraper.
- #scrape_list ⇒ Object
Constructor Details
#initialize(url = nil, score = nil) ⇒ CollectionScraper
Returns a new instance of CollectionScraper.
7 8 9 10 |
# File 'lib/new_game_scores/collection_scraper.rb', line 7 def initialize(url = nil, score = nil) @url = url @score = score end |
Instance Attribute Details
#game_url ⇒ Object
Returns the value of attribute game_url.
3 4 5 |
# File 'lib/new_game_scores/collection_scraper.rb', line 3 def game_url @game_url end |
#metascore ⇒ Object
Returns the value of attribute metascore.
3 4 5 |
# File 'lib/new_game_scores/collection_scraper.rb', line 3 def @metascore end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/new_game_scores/collection_scraper.rb', line 3 def name @name end |
#score ⇒ Object
Returns the value of attribute score.
3 4 5 |
# File 'lib/new_game_scores/collection_scraper.rb', line 3 def score @score end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/new_game_scores/collection_scraper.rb', line 3 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/new_game_scores/collection_scraper.rb', line 3 def url @url end |
#userscore ⇒ Object
Returns the value of attribute userscore.
3 4 5 |
# File 'lib/new_game_scores/collection_scraper.rb', line 3 def userscore @userscore end |
Class Method Details
.collection ⇒ Object
12 13 14 |
# File 'lib/new_game_scores/collection_scraper.rb', line 12 def self.collection @@collection end |
Instance Method Details
#clear ⇒ Object
16 17 18 |
# File 'lib/new_game_scores/collection_scraper.rb', line 16 def clear @@collection.clear end |
#display_list ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/new_game_scores/collection_scraper.rb', line 35 def display_list @@collection.each_with_index do |game, i| game.each do |key, value| if key = :metasocre && value.to_i >= @score.to_i puts " \n#{i+1}. #{game[:title]} \n \n Metascore: #{game[:metascore]} \n Userscore: #{game[:userscore]} \n Release Date: #{game[:release_date]}\n Game Link: #{game[:game_url]}\n \n" end end end end |
#scrape_list ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/new_game_scores/collection_scraper.rb', line 20 def scrape_list game_list = Nokogiri::HTML(open(self.url, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE, 'User-Agent' => 'safari')) game_list.css("ol.list_products li.game_product").each do |game| @@collection << { :title => game.css("div.product_title a").text.strip, :metascore => game.css("div.metascore_w").text, :userscore => game.css("li.product_avguserscore span.textscore").text, :release_date => game.css("li.release_date span.data").text, :game_url => 'http://www.metacritic.com/' +game.css("div.product_title a").attribute("href").text } end end |