diff --git a/app.rb b/app.rb index f068eb5..650a7ca 100644 --- a/app.rb +++ b/app.rb @@ -1,5 +1,11 @@ +require_relative 'genre' +require_relative 'music_album' +require_relative 'book' + class App def initialize + @albums = [] + @genres = [] @books_list = [] end @@ -9,7 +15,19 @@ def list_all_books else puts "\n List 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 "#{index}: #{book.label.title} by #{book.autor.first_name} #{book.author.last_name}" + end + + def list_all_albums + if @albums.empty? + puts "\nThis is empty! :(" + else + puts "\nList all albums" + @albums.each do |element| + puts "ID: #{element.id} + Published day: #{element.publish_date} + Archived: #{element.archived ? 'Yes' : 'No'} + Spotify: #{element.on_spotify ? 'Yes' : 'No'}" end end end @@ -35,11 +53,54 @@ def add_a_book create_book(publish_date, publisher, cover_state, genre, author_name, author_last_name, title, color) end - def create_book + def create_book(publish_date, publisher, cover_state, genre, author_name, author_last_name, title, color) new_book = Book.new(publish_date, publisher, cover_state) new_book.genre = Genre.new(genre) new_book.author = Author.new(author_name, author_last_name) new_book.label = Label.new(title, color) @books_list << new_book end + + def add_a_music_album + print 'Add a Published date:' + publish_date = gets.chomp.to_s + + print 'Is it on Spotify? [y/n]:' + on_spotify = gets.chomp.upcase == 'Y' + + print 'Add a genre:' + genre = Genre.new(gets.chomp.to_s) + + # print 'Add a label:' + # label = Label.new(gets.chomp.to_s) + + # print 'Add a author:' + # author = Author.new(gets.chomp.to_s) + + new_album = MusicAlbum.new(publish_date, on_spotify: on_spotify) + + new_album.genre = genre + # new_album.label = label + # new_album.author = author + new_album.move_to_archived + + @albums << new_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 + end end diff --git a/genre.rb b/genre.rb index b6b1fb4..4103c5f 100644 --- a/genre.rb +++ b/genre.rb @@ -1,7 +1,7 @@ require_relative 'item' class Genre - attr_accessor :name + attr_accessor :name, :id, :items def initialize(name, id = nil) @id = id || Random.rand(1..1000) @@ -15,8 +15,4 @@ def add_item(item) @items << item item.genre = self end - - private - - attr_accessor :id, :items end diff --git a/item.rb b/item.rb index c28efe2..8538483 100644 --- a/item.rb +++ b/item.rb @@ -4,18 +4,18 @@ class Item attr_accessor :id, :publish_date, :archived attr_reader :genre, :author, :label - def initialize(publish_date, id = nil) + def initialize(publish_date, id, archived) @id = id || Random.rand(1..1000) @publish_date = publish_date - @archived = false + @archived = archived @genre = [] @author = [] @label = [] end def genre=(genre) - @genre = genre - genre.genres.push(self) unless genre.genres.include?(self) + @genre = genre.name + genre.items.push(self) unless genre.items.include?(self) end def author=(author) diff --git a/music_album.rb b/music_album.rb index 496465c..44e157a 100644 --- a/music_album.rb +++ b/music_album.rb @@ -1,10 +1,10 @@ require_relative 'item' class MusicAlbum < Item - attr_accessor :on_spotify, :archived + attr_accessor :on_spotify - def initialize(publish_date, on_spotify: false) - super(publish_date) + def initialize(publish_date, id = nil, on_spotify: false, archived: false) + super(publish_date, id, archived) @on_spotify = on_spotify end