Library System
Learn about class methods and class variables by implementing a simplified library system.
We'll cover the following...
We'll cover the following...
Problem
Implement a simplified library system that supports the following functionality:
Initially, the librarian can import book records into the system via a
CSVfile.Members of the library can borrow and return books.
Format of the CSV file
Other than the first line (header), each row in the CSV file has a comma-separated list of the book titles and the authors.
TITLE, AUTHORThe 4-Hour Workweek, Timothy FerrissHow to Win Friends and Influence People, Dale Carnegie# ...
Example use of the library system
# Importing the books from a CSV fileLibrary.import_books(File.join(File.dirname(__FILE__), "files","books.csv"))puts "Number of books: #{Library.book_count}" # => Number of books: 10# Adding new membersjohn = Member.new("John Sully", "1001")mike = Member.new("Mike Zasky", "1002")book = Library.find_by_title("Name of the Fourth Book")Library.borrow(john, book)# Output: "John Sully borrowed 'Name of the Fourth Book'"Library.borrow(mike, book)# Output: The book 'Name of the Fourth Book' is not available!Library.return(book)Library.borrow(mike, book)# Output: "Mike Zasky borrowed 'Name of the Fourth Book'"
Using the library system
Purpose
Work with class methods
Work with class variables
Learn more about class design
Load
CSVdata into objectsFind matching objects in an array ...