From 33bc587c6b96336bf8b39420173b53f7b83c7bf5 Mon Sep 17 00:00:00 2001 From: Andrea Manuel Date: Tue, 12 Sep 2023 17:16:46 -0600 Subject: [PATCH 1/5] Fix inheritance in book class --- app.rb | 2 +- book.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app.rb b/app.rb index 913c5b2..a4d022a 100644 --- a/app.rb +++ b/app.rb @@ -67,7 +67,7 @@ def create_label(title, color) end def create_book(publish_date, publisher, cover_state, genre) - new_book = Book.new(publish_date, publisher, cover_state) + new_book = Book.new(publish_date, publisher, cover_state, nil, false) new_book.genre = Genre.new(genre) new_book end diff --git a/book.rb b/book.rb index b11e843..7c585a4 100644 --- a/book.rb +++ b/book.rb @@ -3,11 +3,10 @@ class Book < Item attr_accessor :publisher, :cover_state - def initialize(publish_date, publisher, cover_state, id = nil) - super(publish_date, id) + def initialize(publish_date, publisher, cover_state, id, archived) + super(publish_date, id, archived) @publisher = publisher @cover_state = cover_state - # @books_list = [] end def can_be_archived? From a43d4b067c1fcb2584f1083fed6f3397b774df32 Mon Sep 17 00:00:00 2001 From: Andrea Manuel Date: Tue, 12 Sep 2023 19:35:54 -0600 Subject: [PATCH 2/5] Edit label setter with the correct relationship in label class --- item.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/item.rb b/item.rb index 8538483..2364160 100644 --- a/item.rb +++ b/item.rb @@ -25,7 +25,7 @@ def author=(author) def label=(label) @label = label - label.labels.push(self) unless label.labels.include?(self) + label.items.push(self) unless label.items.include?(self) end def move_to_archived From 0832cc3a5d5bad724edc8c8079f444abd3c7ceaf Mon Sep 17 00:00:00 2001 From: Andrea Manuel Date: Tue, 12 Sep 2023 19:36:16 -0600 Subject: [PATCH 3/5] Create the Label class --- label.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 label.rb diff --git a/label.rb b/label.rb new file mode 100644 index 0000000..d261cad --- /dev/null +++ b/label.rb @@ -0,0 +1,17 @@ +require_relative 'item' + +class Label + attr_reader :items, :title, :color, :id + + def initialize(title, color, id = nil) + @id = id || Random.rand(1...1000) + @title = title + @color = color + @items = [] + end + + def add_item(item) + @items << item + item.label = self + end +end From cd03a2e006ce632baba7b8eceb0050b847b6d7fe Mon Sep 17 00:00:00 2001 From: Andrea Manuel Date: Tue, 12 Sep 2023 19:39:21 -0600 Subject: [PATCH 4/5] Add method to list all labels in the App class --- app.rb | 69 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/app.rb b/app.rb index a4d022a..d97c446 100644 --- a/app.rb +++ b/app.rb @@ -1,21 +1,24 @@ require_relative 'genre' require_relative 'music_album' require_relative 'book' +require_relative 'author' +require_relative 'label' class App def initialize @albums = [] @genres = [] @books_list = [] + @labels = [] end - def list_all_books - if @books_list.empty? - puts "\nThere is no books yet" + def list_all_genre + if @genres.empty? + puts "\nThis is empty! :(" else - puts "\nList of books" - @books_list.each_with_index do |book, index| - puts "#{index}: #{book.label.title} by #{book.autor.first_name} #{book.author.last_name}" + puts "\nList all albums" + @genres.each do |element| + puts " ID: #{element.id}, Genre: #{element.name}" end end end @@ -34,22 +37,43 @@ def list_all_albums end end + def list_all_books + if @books_list.empty? + puts "\nThere is no books yet" + else + puts "\nList of books" + @books_list.each_with_index do |book, index| + puts "#{index}: #{book.label.title} by #{book.author.first_name} #{book.author.last_name}" + end + end + end + + def list_all_labels + if @labels.empty? + puts "\nThere is no labels yet" + else + @labels.each_with_index do |label, index| + puts "#{index}: #{label.title}, #{label.color}" + end + end + end + def add_a_book - p "Book's tittle: " + print "Book's tittle: " title = gets.chomp - p "Author's first name: " + print "Author's first name: " author_name = gets.chomp - p "Author's last name: " + print "Author's last name: " author_last_name = gets.chomp - p "Book's publish date [dd/mm/yyyy]: " + print "Book's publish date [dd/mm/yyyy]: " publish_date = gets.chomp - p "Book's publisher: " + print "Book's publisher: " publisher = gets.chomp - p "Book's genre: " + print "Book's genre: " genre = gets.chomp - p "Book's cover color" + print "Book's cover color: " color = gets.chomp - p "Book's cover state: " + print "Book's cover state: " cover_state = gets.chomp book = create_book(publish_date, publisher, cover_state, genre) @@ -59,11 +83,13 @@ def add_a_book end def create_author(author_name, author_last_name) - Author.new(author_name, author_last_name) + Author.new(nil, author_name, author_last_name) end def create_label(title, color) - Label.new(title, color) + label = Label.new(title, color) + @labels << label + label end def create_book(publish_date, publisher, cover_state, genre) @@ -99,17 +125,6 @@ def add_a_music_album @genres << genre end - def list_all_genre - if @genres.empty? - puts "\nThis is empty! :(" - else - puts "\nList all albums" - @genres.each do |element| - puts " ID: #{element.id}, Genre: #{element.name}" - end - end - end - def end_app puts 'Thank you for using this app (•◡•)丿' exit From 507512d2cff71da4a94fd369fbccbb16bd0a8244 Mon Sep 17 00:00:00 2001 From: Andrea Manuel Date: Wed, 13 Sep 2023 09:43:41 -0600 Subject: [PATCH 5/5] Correct the send of the author parameters --- app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.rb b/app.rb index d97c446..205b6c8 100644 --- a/app.rb +++ b/app.rb @@ -83,7 +83,7 @@ def add_a_book end def create_author(author_name, author_last_name) - Author.new(nil, author_name, author_last_name) + Author.new(first_name: author_name, last_name: author_last_name) end def create_label(title, color)