Class: Game
- Inherits:
-
Object
- Object
- Game
- Defined in:
- lib/new_games/game.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#price ⇒ Object
Returns the value of attribute price.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .all ⇒ Object
- .doc ⇒ Object
- .find(id) ⇒ Object
- .game_price ⇒ Object
- .game_publisher ⇒ Object
- .product_title ⇒ Object
- .release_date ⇒ Object
- .scrape_all ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
5 6 7 |
# File 'lib/new_games/game.rb', line 5 def date @date end |
#price ⇒ Object
Returns the value of attribute price.
5 6 7 |
# File 'lib/new_games/game.rb', line 5 def price @price end |
#publisher ⇒ Object
Returns the value of attribute publisher.
5 6 7 |
# File 'lib/new_games/game.rb', line 5 def publisher @publisher end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/new_games/game.rb', line 5 def title @title end |
Class Method Details
.all ⇒ Object
9 10 11 |
# File 'lib/new_games/game.rb', line 9 def self.all @@all end |
.doc ⇒ Object
21 22 23 |
# 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) ⇒ Object
17 18 19 |
# File 'lib/new_games/game.rb', line 17 def self.find(id) self.all[id.to_i - 1] end |
.game_price ⇒ Object
29 30 31 |
# 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 ⇒ Object
33 34 35 |
# 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 ⇒ Object
25 26 27 |
# 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 ⇒ Object
37 38 39 |
# 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 ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |
Instance Method Details
#save ⇒ Object
13 14 15 |
# File 'lib/new_games/game.rb', line 13 def save @@all << self end |