Class: BookStoreRun

Inherits:
Object
  • Object
show all
Defined in:
lib/bookstore_run.rb

Overview

BookStore Execution

Class Method Summary collapse

Class Method Details

.startObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bookstore_run.rb', line 5

def self.start
  book_store = BookStore.instance

  puts 'Welcome to the book store'
  puts 'What would you like to do'
  puts '1. Add a book'
  puts '2. Search for a book'
  puts '3. Delete a book'
  puts '4. View all the books'
  puts 'Enter your choice (1-4)'

  choice = gets.chomp
  case choice
  when '1'
    puts 'Enter title of book'
    title = gets.chomp
    if book_store.book_exists(title.intern)
      puts 'Sorry, the book already exists in our store'
    else
      puts 'Enter book rating'
      rating = gets.chomp
      book_store.add_book(title, rating)
      puts 'Book added to store'
    end
  when '2'
    puts 'What would you like to search for'
    search = gets.chomp
    books = book_store.search_book(search)

    if !books.empty?
      books.each do |book|
        puts "Book Name: #{book.title}"
        puts "Book Rating: #{book.rating}"
      end
    else
      puts 'No book found'
    end
  when '3'
    puts 'Enter title of book'
    title = gets.chomp
    if book_store.book_exists(title.intern)
      book_store.delete_book(title)
      puts 'Book removed from store'
    else
      puts 'Sorry, that book does not exist in our store'
    end
  when '4'
    book_store.display_books
  else
    puts 'Invalid input entered'
  end
end