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.
- 📙 About the project
- 💻 Getting Started
- 👥 Author
- 🔭 Future Features
- 🤝 Contributing
- ⭐️ Show your support
- 🙏 Acknowledgements
- 📝 License
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:
- Add new students or teachers.
- Add new books.
- Save records of who borrowed a given book and when.
-
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.
-
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.
-
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.
-
-
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.
Create in a separate file each of the below classes:
- Instance vars:
@id
,@name
, and@age
. - Constructor with
name
,age
, andparent_permission
as parameter.name
andparent_permission
are optional and have default values of"Unknown"
andtrue
. - Getters for
@id
,@name
, and@age
. - Setters for
@name
and@age
. - Private method
of_age?
that returnstrue
if@age
is greater or equal to 18 andfalse
otherwise. - Public method
can_use_services?
that returnstrue
if person is of age 18 or if they have permission from parents.
- Inherits from Person.
- Constructor extends parent's constructor by adding
@classroom
and a parameter for it. - Method
play_hooky
that returns¯\(ツ)/¯
.
- Inherits from Person.
- Constructor extends parent's constructor by adding
@specialization
and a parameter for it. - Override
can_use_services?
so it always returnstrue
.
Think about how you can use two decorators in order to capitalize and trim people's names.
- Create a class Nameable.
- Implement a method called
correct_name
that will raise aNotImplementedError
.
- Make sure that your Person class inherits from Nameable
- Make sure that this class has a method
correct_name
implemented. It should simply return thename
attribute.
- 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 thecorrect_name
method of the@nameable
.
- 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.
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
student = Student.new(22, 'maximilianus', false, chemistry)
book1 = Book.new('chemistry for nubbies', 'ruth green')
book2 = Book.new('chemistry advanced', 'john fitzgerald')
teacher = Teacher.new(22, 'mr. smith', 'chemistry')
teacher.add_rental('05/25/2023', book1)
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: [] ... ...
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 inIRB
exclusively.Our Library Manager should behave in the same way as in the following example.
- Create a
app.rb
file that will serve as your console appentry-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
.
- In your
main.rb
define theentry-point
, this will be a method calledmain
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.
- 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
- Instance vars:
To get a local copy of this project up and running, follow these steps.
-
- 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 installgit
. - Also you must have
Ruby
installed, you can go to the Installing Ruby documentation and follow the steps for your computer OS.
- In order to run this project locally you need
-
Clone this repository to your desired folder:
cd my-folder git clone git@github.com:luigirazum/library-manager.git
-
In the folder where you cloned the project, go into the project folder
cd library-manager
-
In the
library-manager
folder, use the following code to run the app./main
👨💻 Luis Zubia
- ❇️ 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.
- ❇️ 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.
- ❇️ 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.
Contributions, issues, typos, and feature requests are welcome!
Feel free to check the issues page.
If you like this project, your support giving a ⭐ will be highly appreciated.
- I would like to thank Yukihiro “Matz” Matsumoto for creating the Ruby Programming Language.
This project is MIT licensed.