class Game
Attributes
date[RW]
price[RW]
publisher[RW]
title[RW]
Public Class Methods
all()
click to toggle source
# File lib/new_games/game.rb, line 9 def self.all @@all end
doc()
click to toggle source
# File lib/new_games/game.rb, line 21 def self.doc @@doc ||= Nokogiri::HTML(open("http://www.gamestop.com/browse/games/xbox-one?nav=28-xu0,13ffff2418-1e0-5")) end
find(id)
click to toggle source
# File lib/new_games/game.rb, line 17 def self.find(id) self.all[id.to_i - 1] end
game_price()
click to toggle source
# File lib/new_games/game.rb, line 29 def self.game_price @@price ||= doc.search(".ats-product-price").collect{|e| e.text} end
game_publisher()
click to toggle source
# File lib/new_games/game.rb, line 33 def self.game_publisher @@publisher ||= doc.search(".ats-product-publisher").collect{|e| e.text} end
product_title()
click to toggle source
# File lib/new_games/game.rb, line 25 def self.product_title @@title ||= doc.search(".ats-product-title a").collect{|e| e.text} end
release_date()
click to toggle source
# File lib/new_games/game.rb, line 37 def self.release_date @@date ||= doc.search(".ats-product-infoList li:first-child").collect{|e| e.text} end
scrape_all()
click to toggle source
# File lib/new_games/game.rb, line 41 def self.scrape_all (0..product_title.size-1).to_a.each do |i| title = product_title[i] price = game_price[i] publisher = game_publisher[i] date = release_date[i] game = Game.new game.title = title game.price = price game.publisher = publisher game.date = date game.save end end
Public Instance Methods
save()
click to toggle source
# File lib/new_games/game.rb, line 13 def save @@all << self end