Skip to content

Imagine that you are the librarian of OOP University, and you need a tool to record what books are in the library and who borrows them. The Library Manager you'll create will allow you to: Add new students or teachers. Add new books. Save records of who borrowed a given book and when. And all of this will be built in a beautiful, organized way.

License

Notifications You must be signed in to change notification settings

luigirazum/library-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

Libray Manager

is a simple App created with Ruby using OOP (Object Oriented Programming) which enables you to record what books are in the library and who borrows them. The app allows you to:
1️⃣ Add new students or teachers.
2️⃣ Add new books.
3️⃣ Save records of who borrowed a given book and when.


📗 Table of Contents


📙 Library Manager

Library Manager is a simple App created with Ruby Programming Language using OOP (Object Oriented Programming) which enables you to record what books are in the library and who borrows them. The app allows you to:

  1. Add new students or teachers.
  2. Add new books.
  3. Save records of who borrowed a given book and when.
  • How to do the App

    We will start by building the most essential pieces of the app(system). To do that, we will practice Object Oriented Programming(OOP). To build the app or system we will need to create the entities presented in the following Class diagram.

    • 📈 UML Class Diagram

      The image below is a UML(Unified Modeling Language) class diagram, it can give you an overall idea of what we are going to build.

    • 🖥️ Simple UI (User Interface)

      Once you have the core part prepared, we will create a simple UI layer which will be a console app interacting with the user. The final result will be similar to the one presented in the demo below.

🛠 Built With

  • Key Features

    We'll be building the Library Manager app according to the following list of projects that will guide you through the steps described above. The details about each of these projects will be added on every feature implementation.

    Project 1️⃣🔹Add Person, Student, and Teacher classes.

    Create in a separate file each of the below classes:

    ✳️ Class Person with the following:

    • Instance vars: @id, @name, and @age.
    • Constructor with name, age, and parent_permission as parameter. name and parent_permission are optional and have default values of "Unknown" and true.
    • Getters for @id, @name, and @age.
    • Setters for @name and @age.
    • Private method of_age? that returns true if @age is greater or equal to 18 and false otherwise.
    • Public method can_use_services? that returns true if person is of age 18 or if they have permission from parents.

    ✳️ Class Student with the following:

    • Inherits from Person.
    • Constructor extends parent's constructor by adding @classroom and a parameter for it.
    • Method play_hooky that returns ¯\(ツ)/¯.

    ✳️ Class Teacher with the following:

    • Inherits from Person.
    • Constructor extends parent's constructor by adding @specialization and a parameter for it.
    • Override can_use_services? so it always returns true.

    2️⃣ Use the Decorator design pattern.

    Think about how you can use two decorators in order to capitalize and trim people's names.

    ✳️ Interface

    • Create a class Nameable.
    • Implement a method called correct_name that will raise a NotImplementedError.

    ✳️ Turn your Person class to Nameable

    • Make sure that your Person class inherits from Nameable
    • Make sure that this class has a method correct_name implemented. It should simply return the name attribute.

    ✳️ Prepare base Decorator

    • Make sure that it inherits from Nameable.
    • In the constructor assign a nameable object from params to an instance variable.
    • Implement the correct_name method that returns the result of the correct_name method of the @nameable.

    ✳️ Prepare CapitalizeDecorator and TrimmerDecorator

    • For the CapitalizeDecorator:
      • Create a class that inherits from the base Decorator class.
      • Implement a method correct_name that capitalizes the output of @nameable.correct_name.
    • For the TrimmerDecorator:
      • Create a class that inherits from the base Decorator class.
      • Implement a method correct_name that makes sure that the output of @nameable.correct_name has a maximum of 10 characters. If it's longer it should trim the word.

    ✳️ See your decorators in action

    Try the following code and check if you managed to decorate your person:

    person = Person.new(22, 'maximilianus')
    person.correct_name
    capitalizedPerson = CapitalizeDecorator.new(person)
    capitalizedPerson.correct_name
    capitalizedTrimmedPerson = TrimmerDecorator.new(capitalizedPerson)
    capitalizedTrimmedPerson.correct_name

    3️⃣ Set up Associations.

    Now, we are going to finish creating the remaining Classes for our **Library Manager** and create the Associations between them. #### ✳️ Create a class Classroom with the following: - `@label` instance variable, should be initialized in the constructor. - Setter and getter for `@label` (remember about `attr_accessor`). #### ✳️ Create the `has-many`/`belongs-to` relationship between Classroom and Student. The following should be implemented: - Create the `has-many` side (a Classroom has many Students). - Create the `belongs-to` side (a Student belongs to a Classroom). - Make sure that when adding a Student to a Classroom it also sets the Classroom for the Student. - Make sure that when setting the Classroom for a Student it also adds it to the Classrooms' Students. #### ✳️ Create a class Book with the following: - `@title` and `@author` instance variables, should be initialized in the constructor. - Setters and getters for instance variables (remember about `attr_accessor`). #### ✳️ Create a class Rental with the following: - `@date` instance variable, should be initialized in the constructor. - Setter and getter for `@date` (remember about `attr_accessor`). #### ✳️ Create the `many-to-many` (also `has-many-through`) relationship between Person and Book using the intermediate class Rental. The following should be implemented: - Create the `has-many` side of Book and Rental (a Book has many Rentals). - Create the `belongs-to` side of Rental and Book (a Rental belongs to a Book). - Create the `has-many` side of Person and Rental (a Person has many Rentals). - Create the `belongs-to` side of Rental and Person (a Rental belongs to a Person). - Modify the constructor of Rental so Book and Person are set in it. #### ✳️ See the Associations in action A 'main.rb' was created on the 'root' folder, you can run it with `>ruby main.rb` to see how the associations work. ```ruby # a chemistry classroom is created chemistry = Classroom.new('chemistry')

    a student is created, he is in chemistry classroom

    student = Student.new(22, 'maximilianus', false, chemistry)

    a book1 is created, it hasn't been rented

    book1 = Book.new('chemistry for nubbies', 'ruth green')

    a book2 is created, it hasn't been rented

    book2 = Book.new('chemistry advanced', 'john fitzgerald')

    a teacher is created, with chemistry specialization

    teacher = Teacher.new(22, 'mr. smith', 'chemistry')

    teacher rents book1 on may 25, 2023

    teacher.add_rental('05/25/2023', book1)

    book2 is rented by student on may 25, 2023

    book2.add_rental('05/25/2023', student)

    The result of the previous code once you ran it should be:
    ```sh
    ❯ ruby main.rb
    ---- create a classroom ---
    classroom: chemistry
    classroom students: []
    
    ---- create a student ---
    student: maximilianus
    student classroom: chemistry
    student rentals: []
    
    ...
    ...
    

    4️⃣ Add basic UI.

    This time we will create a form of UI(User Interface) for our Library Manager. This way it can be invoked as an executable and not something you use in IRB exclusively.

    ✳️ Watch this Console App Example.

    Our Library Manager should behave in the same way as in the following example. UI example

    ✳️ The entry-point

    • Create a app.rb file that will serve as your console app entry-point. It should have methods that do the following:
      • List all Books.
      • List all people.
      • Create a Person (Teacher or Student, not a plain Person).
      • Create a Book.
      • Create a Rental.
      • List all Rentals for a given Person @id.

    ✳️ The script

    • In your main.rb define the entry-point, this will be a method called main that is invoked at the end of your file. This method should do the following:
      • Present the user with a list of options to perform.
      • Lets users choose an option.
      • If needed, ask for parameters for the option.
      • Have a way to quit the app.

    ✳️ Starting the UI

    • Run the app with the following command:
      > main
    • The app will show the main menu in the console
      Welcome! This is the 'Library Manager'
      Please choose an option by entering a number:
      1 - List all books
      2 - List all people
      3 - Create a person
      4 - Create a book
      5 - Create a rental
      6 - List all rentals for a given person
      7 - Exit

    🧑‍💻 to be implemented Features

    Project 5️⃣🔹 Refactoring the code.

    Project 6️⃣🔹Preserve data.

    Project 7️⃣🔹Unit Tests.

(back to top)

💻 Getting Started

To get a local copy of this project up and running, follow these steps.

  • Prerequisites

    • In order to run this project locally you need git installed. Please got to Getting Started - Installing Git guide and follow the steps described for your system to install git.
    • Also you must have Ruby installed, you can go to the Installing Ruby documentation and follow the steps for your computer OS.
  • Setup

    Clone this repository to your desired folder:

    cd my-folder
    git clone git@github.com:luigirazum/library-manager.git
  • Usage

    In the folder where you cloned the project, go into the project folder

    cd library-manager
  • Run

    In the library-manager folder, use the following code to run the app

    ./main

(back to top)

👥 Author

👨‍💻 Luis Zubia

(back to top)

🔭 Future Features

➕ Sorting and Ordering.

  • ❇️ Implement sorting and ordering options for the library data, such as sorting books by title, author, or publication date.
  • ❇️ Make it easier for users to navigate and browse the library's collection.

➕ Reporting Capabilities.

  • ❇️ Develop features that allow users to generate reports or summaries of the library's data, such as a list of borrowed books, overdue books, or books by genre.
  • ❇️ Facilitate better management and analysis of the library's collection and borrowing patterns.

➕ Export and Import Functionality.

  • ❇️ Add the ability to export library data to a file or import data from an external source.
  • ❇️ Allow users to create backups of the library records or import data from other libraries or systems.

(back to top)

🤝 Contributing

Contributions, issues, typos, and feature requests are welcome!

Feel free to check the issues page.

(back to top)

⭐️ Show your support

If you like this project, your support giving a ⭐ will be highly appreciated.

(back to top)

🙏 Acknowledgments

(back to top)

📝 License

This project is MIT licensed.

(back to top)

About

Imagine that you are the librarian of OOP University, and you need a tool to record what books are in the library and who borrows them. The Library Manager you'll create will allow you to: Add new students or teachers. Add new books. Save records of who borrowed a given book and when. And all of this will be built in a beautiful, organized way.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages