Class: UpcomingVideoGames::Game

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

Constant Summary collapse

@@games =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game_hash) ⇒ Game

Returns a new instance of Game.



6
7
8
9
# File 'lib/upcoming_video_games/game.rb', line 6

def initialize(game_hash)
  game_hash.each {|key, value| self.send(("#{key}="), value)}
  @@games << self
end

Instance Attribute Details

#consoleObject

Returns the value of attribute console.



2
3
4
# File 'lib/upcoming_video_games/game.rb', line 2

def console
  @console
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/upcoming_video_games/game.rb', line 2

def description
  @description
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/upcoming_video_games/game.rb', line 2

def name
  @name
end

#priceObject

Returns the value of attribute price.



2
3
4
# File 'lib/upcoming_video_games/game.rb', line 2

def price
  @price
end

Returns the value of attribute purchase_link.



2
3
4
# File 'lib/upcoming_video_games/game.rb', line 2

def purchase_link
  @purchase_link
end

#release_dateObject

Returns the value of attribute release_date.



2
3
4
# File 'lib/upcoming_video_games/game.rb', line 2

def release_date
  @release_date
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/upcoming_video_games/game.rb', line 2

def url
  @url
end

Class Method Details

.create_by_each_game(scraped_games) ⇒ Object



12
13
14
15
16
17
# File 'lib/upcoming_video_games/game.rb', line 12

def self.create_by_each_game(scraped_games)
  scraped_games.each do |game|
    #write a comment to explain release year
    self.new(game) unless game[:release_date] < (DateTime.now) rescue nil
  end
end

.gamesObject



19
20
21
# File 'lib/upcoming_video_games/game.rb', line 19

def self.games
  @@games.sort_by! {|game_obj| game_obj.release_date}
end

Instance Method Details

#add_game_details(details) ⇒ Object



23
24
25
26
# File 'lib/upcoming_video_games/game.rb', line 23

def add_game_details(details)
  details.each {|key, value| self.send(("#{key}="), value)}
  self
end