Class: BookStoreRun

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

Overview

BookStoreRun Class

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
# File 'lib/book_store_run.rb', line 5

def self.start
  book_store = BookStore.instance
  # puts commands to display instructions to the user

  puts 'Welcome to the Ruby Bookstore.'
  puts 'Please choose a follow operation from below to perform.'
  puts 'Type --1-- to add a new book'
  puts 'Type --2-- to find a book of your own choice'
  puts 'Type --3-- to have a list of all available books'
  puts 'Type --4-- to delete a book'
  # getting user's input

  choice = gets.chomp.downcase
  # performing what user wants

  case choice
  when '1'
    puts 'Enter the name of the book you want to add?'
    name = gets.chomp
    if book_store.book_exists(name.intern)
      puts 'Book already exists!'
    else
      puts 'Enter the rating of the book?'
      rating = gets.chomp
      book_store.book_add(name, rating)
      puts 'Book added to the store!'
    end
  when '2'
    puts 'Enter what you want to search?'
    search = gets.chomp
    book_store.book_search(search)
  when '3' then book_store.book_display
  when '4'
    puts 'Enter the name of the book you want to Delete?'
    name = gets.chomp
    if book_store.book_exists(name.intern)
      book_store.book_delete(name)
    else
      puts 'No Book Found'
    end
  else
    puts 'Didn\'t get what you are trying to ask!'
  end
end