diff --git a/app.rb b/app.rb index 6823c00..6b20763 100644 --- a/app.rb +++ b/app.rb @@ -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 diff --git a/classes/author.rb b/classes/author.rb index 0882a9e..cd87f87 100644 --- a/classes/author.rb +++ b/classes/author.rb @@ -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 diff --git a/classes/game.rb b/classes/game.rb index ecf1a23..ca1ebe6 100644 --- a/classes/game.rb +++ b/classes/game.rb @@ -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? diff --git a/main.rb b/main.rb index e995886..d84e9fe 100644 --- a/main.rb +++ b/main.rb @@ -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 @@ -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