Skip to content

Commit

Permalink
Merge branch 'dev' into feature/update-methods-and-options
Browse files Browse the repository at this point in the history
  • Loading branch information
Obimbo07 authored Dec 20, 2023
2 parents c453652 + cb242b7 commit c8194cc
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 4 deletions.
90 changes: 88 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
require './classes/movie'

require './classes/item'
require './classes/book'
require './classes/label'
require './classes/game'
require './classes/source'
require './classes/author'
require './classes/movie'
require './classes/source'

class App
def initialize
@books = []
@labels = []
@authors = []
@movies = []
@sources = []
end

# list methods
def list_all_books
puts "\nListing all books:"
if @books.empty?
puts 'No books found.'
else
@books.each do |book|
puts "ID: #{book.id}, Author: #{book.author.first_name}, Publisher: #{book.publisher},
Cover state: #{book.cover_
end
end
end

def list_all_movies
if @movies.empty?
puts 'No movies were found'
Expand All @@ -16,7 +39,7 @@ def list_all_movies
end
end
end

def list_all_sources
if @sources.empty?
puts 'No sources were found'
Expand All @@ -27,6 +50,18 @@ def list_all_sources
end
end

def list_all_labels
puts "\nListing all labels:"
if @labels.empty?
puts 'No labels found.'
else
@labels.each do |label|
puts "Title: #{label.title}, Color: #{label.color}"
end
end
end

# add methods
def add_movie
puts 'Enter Title: '
title = gets.chomp.to_s
Expand Down Expand Up @@ -56,4 +91,55 @@ def add_movie

puts 'Movie added successfully!'
end

def add_book
puts 'Published by:'
publisher = gets.chomp.to_s
puts 'Cover state (good or bad):'
loop do
@cover_state = gets.chomp.to_s
break if %w[good bad].include?(@cover_state)
return if @cover_state == 'exit'

puts 'Invalid cover state. Please try again or type exit to return to the main menu.'
end

puts 'Published date (YYYY-MM-DD):'
loop do
@publish_date = gets.chomp
break if @publish_date.match?(/\d{4}-\d{2}-\d{2}/)
return if @publish_date == 'exit'

puts 'Invalid date format. Please try again.'
end

book = Book.new(publisher, @cover_state, @publish_date)
choose_label(book)
choose_author(book)

@books << book
end

private

def choose_label(item)
puts 'Label title:'
title = gets.chomp.to_s
puts 'Label color:'
color = gets.chomp.to_s
label = @labels.find { |l| l.title == title } || Label.new(title, color)
@labels << label unless @labels.include?(label)
item.label = label
end

def choose_author(item)
puts 'Authors first name:'
first_name = gets.chomp.to_s
puts 'Authors last name:'
last_name = gets.chomp.to_s
author = @authors.find { |a| a.first_name == first_name && a.last_name == last_name } ||
Author.new(first_name: first_name, last_name: last_name)
@authors << author unless @authors.include?(author)
item.author = author
end
end
4 changes: 2 additions & 2 deletions classes/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class Author
attr_accessor :id, :first_name, :last_name, :items

def initialize(id:, first_name:, last_name:)
@id = id
def initialize(first_name:, last_name:, id: nil)
@id = id || Random.rand(1..1000)
@first_name = first_name
@last_name = last_name
@items = []
Expand Down
18 changes: 18 additions & 0 deletions classes/genre.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require './classes/item'

class Genre < Item
attr_accessor :name
attr_reader :id, :items

def initialize(name, id = nil)
super
@id = id || Random.random(1..1000)
@name = name
@items = []
end

def add_item(item)
@items << item
item.label = self
end
end
14 changes: 14 additions & 0 deletions classes/musicalbum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require './classes/item'

class MusicAlbum < Item
attr_accessor :on_spotify

def initialize(genre, author, source, label, publish_date, on_spotify)
super(genre, author, source, label, publish_date)
@on_spotify = on_spotify
end

def can_be_archived?
super || @on_spotify
end
end

0 comments on commit c8194cc

Please sign in to comment.