Skip to content

Commit

Permalink
Merge branch 'develop' into book-class
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaM2429 authored Sep 12, 2023
2 parents c6efea2 + c21ebcb commit 51d312a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 14 deletions.
65 changes: 63 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
require_relative 'genre'
require_relative 'music_album'
require_relative 'book'

class App
def initialize
@albums = []
@genres = []
@books_list = []
end

Expand All @@ -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
Expand All @@ -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
6 changes: 1 addition & 5 deletions genre.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -15,8 +15,4 @@ def add_item(item)
@items << item
item.genre = self
end

private

attr_accessor :id, :items
end
8 changes: 4 additions & 4 deletions item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions music_album.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 51d312a

Please sign in to comment.