Skip to content

Commit

Permalink
Updated files for author and games
Browse files Browse the repository at this point in the history
  • Loading branch information
DevKaranJ committed Dec 22, 2023
1 parent 8e9c8cd commit e12419f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
8 changes: 7 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ def add_game
print 'Enter last played date (YYYY-MM-DD): '
last_played_at = gets.chomp

game = Game.new(genre, author, source, label, publish_date, multiplayer, last_played_at)
# Modified code: Create a new Game object with the correct parameters
game = Game.new(publish_date, multiplayer, last_played_at)
game.genre = genre
game.author = author
game.source = source
game.label = label

game.move_to_archive if game.can_be_archived?

@games << game
Expand Down
8 changes: 8 additions & 0 deletions classes/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def initialize(id: nil, first_name:, last_name:)
@@all_authors << self
end

def to_json(*args)
{
'id' => @id,
'first_name' => @first_name,
'last_name' => @last_name
}.to_json(*args)
end

def add_item(item)
@items << item
item.author = self
Expand Down
21 changes: 17 additions & 4 deletions classes/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@
class Game < Item
attr_accessor :multiplayer, :last_played_at

@@all_games = []
# Class variable to store all game instances

def initialize(genre, author, source, label, publish_date, multiplayer, last_played_at)
super(genre, author, source, label, publish_date)
def initialize(publish_date, multiplayer, last_played_at)
super(nil, nil, multiplayer, last_played_at, publish_date)
@multiplayer = multiplayer
@last_played_at = last_played_at
@publish_date = Date.parse(publish_date)
end

@@all_games << self
def to_json(*args)
{
JSON.create_id => self.class.name,
'id' => @id,
'genre' => @genre,
'author' => @author,
'source' => @source,
'label' => @label,
'publish_date' => @publish_date,
'archived' => @archived,
'multiplayer' => @multiplayer,
'last_played_at' => @last_played_at
}.to_json(*args)
end

def can_be_archived?
Expand Down
6 changes: 3 additions & 3 deletions main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def run_options(choice)
when 3
@app.list_all_movies
when 4
list_all_games
@app.list_all_games
when 5
@app.list_all_genres
when 6
@app.list_all_labels
when 7
list_all_authors
@app.list_all_authors
when 8
@app.list_all_sources
when 9
Expand All @@ -49,7 +49,7 @@ def run_options(choice)
when 11
@app.add_movie
when 12
add_game
@app.add_game
else
puts 'Invalid option. Please try again.'
end
Expand Down

0 comments on commit e12419f

Please sign in to comment.