Class: BookStore
- Inherits:
-
Object
- Object
- BookStore
- Defined in:
- lib/bookstore.rb
Overview
Bookstore running script
Instance Method Summary collapse
- #add_book(title) ⇒ Object
- #add_case ⇒ Object
- #decide_update(title) ⇒ Object
- #delete_case ⇒ Object
-
#initialize ⇒ BookStore
constructor
A new instance of BookStore.
- #main_message ⇒ Object
- #main_store ⇒ Object
- #search_all_case ⇒ Object
- #update_case ⇒ Object
Constructor Details
#initialize ⇒ BookStore
Returns a new instance of BookStore.
6 7 8 |
# File 'lib/bookstore.rb', line 6 def initialize puts 'Store initialized!' end |
Instance Method Details
#add_book(title) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/bookstore.rb', line 52 def add_book(title) puts 'What is the rating of the book?' = gets.chomp bs = BookStoreCore.new book = bs.add_update_book(title, , bs.readf('fi.json')) bs.writef('fi.json', book) puts 'Added successfully.' end |
#add_case ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bookstore.rb', line 41 def add_case puts 'What is the title of the book?' title = gets.chomp bs = BookStoreCore.new if bs.is_exist(title, bs.readf('fi.json')) puts 'This book already exist.' else add_book(title) end end |
#decide_update(title) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bookstore.rb', line 67 def decide_update(title) bs = BookStoreCore.new if bs.is_exist(title, bs.readf('fi.json')) puts 'What is the rating of the book?' = gets.chomp book = bs.add_update_book(title, , bs.readf('fi.json')) bs.writef('fi.json', book) puts 'Updated successfully.' else puts 'This book does not exist.' end end |
#delete_case ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bookstore.rb', line 80 def delete_case puts 'Which book do you want to delete?' title = gets.chomp bs = BookStoreCore.new if bs.is_exist(title, bs.readf('fi.json')) book_hash = bs.delete_book(title, bs.readf('fi.json')) bs.writef('fi.json', book_hash) puts 'Deleted successfully.' else puts 'This book does not exist.' end end |
#main_message ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bookstore.rb', line 23 def puts 'What would you like to do?' puts "-- Type 'add' to Add a book." puts "-- Type 'update' to Update a book." puts "-- Type 'search' to Display all books." puts "-- Type 'all' to Display all books." puts "-- Type 'delete' to Delete a book." choice = gets.chomp.downcase choice end |
#main_store ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bookstore.rb', line 10 def main_store case when 'add' then add_case when 'update' then update_case when 'search' then search_all_case when 'all' bs = BookStoreCore.new puts bs.get_all_books(bs.readf('fi.json')) when 'delete' then delete_case else puts 'Sorry, wrong input!' end end |
#search_all_case ⇒ Object
34 35 36 37 38 39 |
# File 'lib/bookstore.rb', line 34 def search_all_case puts 'Please add starting characters.' start_chars = gets.chomp bs = BookStoreCore.new puts bs.get_full_title(start_chars, bs.readf('fi.json')) end |
#update_case ⇒ Object
61 62 63 64 65 |
# File 'lib/bookstore.rb', line 61 def update_case puts 'Which book do you want to update?' title = gets.chomp decide_update(title) end |