Library System

Learn about class methods and class variables by implementing a simplified library system.

Problem

Implement a simplified library system that supports the following functionality:

  • Initially, the librarian can import book records into the system via a CSV file.

  • 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, AUTHOR
The 4-Hour Workweek, Timothy Ferriss
How to Win Friends and Influence People, Dale Carnegie
# ...

Example use of the library system

# Importing the books from a CSV file
Library.import_books(File.join(File.dirname(__FILE__), "files","books.csv"))
puts "Number of books: #{Library.book_count}" # => Number of books: 10
# Adding new members
john = 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 CSV data into objects

  • Find matching objects in an array ...

Analyze