Skip to content

Commit

Permalink
Display author fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
DevKaranJ committed Dec 21, 2023
1 parent cc2f478 commit 5fa4065
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def list_all_authors
end
end
end

# add methods
def add_book
puts 'Published by:'
Expand Down Expand Up @@ -95,7 +95,10 @@ def add_game
genre = gets.chomp
print 'Enter author (full name): '
author_name = gets.chomp
author = Author.find_by_full_name(author_name) || Author.new(first_name: author_name.split.first, last_name: author_name.split.last)

# Modified code: Find or create the author based on full name
author = find_or_create_author(author_name)

print 'Enter source: '
source = gets.chomp
print 'Enter label: '
Expand All @@ -117,6 +120,19 @@ def add_game

private

# Modified code: Method to find or create an author based on full name
def find_or_create_author(full_name)
first_name, last_name = full_name.split
author = @authors.find { |a| a.first_name == first_name && a.last_name == last_name }

unless author
author = Author.new(first_name: first_name, last_name: last_name)
@authors << author
end

author
end

def choose_label(item)
puts 'Label title:'
title = gets.chomp.to_s
Expand Down

0 comments on commit 5fa4065

Please sign in to comment.