-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from tafaramafemba/book-label
Book, Label and methods
- Loading branch information
Showing
9 changed files
with
140 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require_relative './classes/book' | ||
|
||
class App | ||
attr_reader :all_books | ||
|
||
def initialize | ||
@all_books = [] | ||
end | ||
|
||
def list_books | ||
puts "\nAll books" | ||
|
||
if @all_books.length.zero? | ||
puts 'Book list is empty. Choose option (7) to add a book' | ||
else | ||
@all_books.each do |book| | ||
puts "Publication Date: #{book.published_date}, Publisher: #{book.publisher}, State: #{book.cover_state}" | ||
end | ||
end | ||
end | ||
|
||
def add_book | ||
puts "\nAdd a book" | ||
print 'Date of publication [yyyy-mm-dd]: ' | ||
published_date = gets.chomp | ||
print 'Publisher: ' | ||
publisher = gets.chomp | ||
print "Cover state (Enter 'good' or 'bad'): " | ||
cover_state = gets.chomp | ||
new_book = Book.new(published_date, publisher, cover_state) | ||
@all_books.push(new_book) | ||
puts 'Book added successfully!' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require_relative 'item' | ||
|
||
class Book < Item | ||
attr_reader :publisher, :cover_state | ||
attr_accessor :published_date | ||
|
||
def initialize(published_date, publisher, cover_state) | ||
super(id, published_date) | ||
@id = rand(1..1000) | ||
@publisher = publisher | ||
@cover_state = cover_state | ||
end | ||
|
||
def can_be_archived? | ||
super || @cover_state == 'bad' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require_relative 'menu' | ||
|
||
def main | ||
puts "\nWelcome to your catalogue!" | ||
menu | ||
end | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require_relative 'app' | ||
|
||
def app_options | ||
puts "\nPlease choose an option to continue: " | ||
puts '1 - List all books' | ||
puts '2 - List all music albums' | ||
puts '3 - List of games' | ||
puts '4 - List all genres' | ||
puts '5 - List all labels' | ||
puts '6 - List all authors' | ||
puts '7 - Add a book' | ||
puts '8 - Add a music album' | ||
puts '9 - Add a game' | ||
puts '10 - Exit' | ||
puts | ||
end | ||
|
||
def menu # rubocop:disable Metrics/CyclomaticComplexity | ||
app = App.new | ||
|
||
loop do | ||
app_options | ||
option = gets.chomp.to_i | ||
|
||
case option | ||
when 1 then app.list_books | ||
when 2 then app.list_albums | ||
when 3 then app.list_games | ||
when 4 then app.list_genres | ||
when 5 then app.list_labels | ||
when 6 then app.list_authors | ||
when 7 then app.add_book | ||
when 8 then app.add_album | ||
when 9 then app.add_game | ||
when 10 | ||
abort("Have a nice day \n\n") | ||
else | ||
puts 'Invalid selection' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require_relative '../classes/book' | ||
|
||
describe Book do | ||
context 'Testing Book class' do | ||
before :each do | ||
@book1 = Book.new('2010-03-14', 'Cambridge', 'good') | ||
@book2 = Book.new('2020-01-24', 'Oxford', 'good') | ||
@book3 = Book.new('2018-10-06', 'Penguin', 'bad') | ||
end | ||
|
||
it 'returns child of Item' do | ||
expect(@book1).to be_kind_of(Item) | ||
end | ||
|
||
it 'returns instance of Book' do | ||
expect(@book1).to be_instance_of(Book) | ||
end | ||
|
||
it 'returns published date' do | ||
expect(@book1.published_date).to eq Date.parse('2010-03-14') | ||
end | ||
|
||
it 'checks if book can be achived' do | ||
expect(@book1.can_be_archived?).to eq true | ||
end | ||
|
||
it 'checks if book can be achived' do | ||
expect(@book2.can_be_archived?).to eq false | ||
end | ||
|
||
it 'checks if book can be achived' do | ||
expect(@book3.can_be_archived?).to eq true | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.