Class: Game

Inherits:
Object
  • Object
show all
Defined in:
lib/new_games/game.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dateObject

Returns the value of attribute date.



5
6
7
# File 'lib/new_games/game.rb', line 5

def date
  @date
end

#priceObject

Returns the value of attribute price.



5
6
7
# File 'lib/new_games/game.rb', line 5

def price
  @price
end

#publisherObject

Returns the value of attribute publisher.



5
6
7
# File 'lib/new_games/game.rb', line 5

def publisher
  @publisher
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/new_games/game.rb', line 5

def title
  @title
end

Class Method Details

.allObject



9
10
11
# File 'lib/new_games/game.rb', line 9

def self.all 
  @@all 
end

.docObject



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_priceObject



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_publisherObject



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_titleObject



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_dateObject



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_allObject



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

#saveObject



13
14
15
# File 'lib/new_games/game.rb', line 13

def save
  @@all << self 
end