Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add album #31

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
require_relative 'genre'
require_relative 'music_album'

class App
def initialize
puts 'Hello World'
@albums = []
@genres = []
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

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
Loading