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

Create Label class and implement methods #33

Merged
merged 5 commits into from
Sep 13, 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
71 changes: 43 additions & 28 deletions app.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -59,15 +83,17 @@ def add_a_book
end

def create_author(author_name, author_last_name)
Author.new(author_name, author_last_name)
Author.new(first_name: author_name, last_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)
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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions label.rb
Original file line number Diff line number Diff line change
@@ -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
Loading