Excerpt
# Building a CLI App with Ruby

Megan Dacus
4 min read
·
Jun 9, 2023
- -
Listen
Share
For my phase-3 project in my full-stack developer course, I was tasked with creating a Command Line Interface Application using Ruby. CLI applications are tools that allow users to interact with programs directly from the terminal without needing a graphical user interface.
In this blog, I will be outlining how I built the application, what the features are, and what I learned from the process.
## Building the App
### The Planning
I had a general idea of what I wanted to do with this project but had to change it a few times due to access to APIs. I always wanted to have an app that could access book information and create a personal “bookshelf” of favorites. I am a reader, so making applications that I would be interested in using myself has made the process so much more fun.
After some research of a few differe
# Building a CLI App with Ruby

Megan Dacus
4 min read
·
Jun 9, 2023
- -
Listen
Share
For my phase-3 project in my full-stack developer course, I was tasked with creating a Command Line Interface Application using Ruby. CLI applications are tools that allow users to interact with programs directly from the terminal without needing a graphical user interface.
In this blog, I will be outlining how I built the application, what the features are, and what I learned from the process.
## Building the App
### The Planning
I had a general idea of what I wanted to do with this project but had to change it a few times due to access to APIs. I always wanted to have an app that could access book information and create a personal “bookshelf” of favorites. I am a reader, so making applications that I would be interested in using myself has made the process so much more fun.
After some research of a few different public book API’s I discovered that Google Books had all of the functionality I wanted. Doing this API research gave me a good understanding of how different API’s work and helped me to develop some fundamental knowledge that I may not have gained otherwise.
Once I had access to a useful API and a concept for what I wanted the app to do, I set out to determining which databases and classes I would need to set up and how each of those databases and classes would interact with each other. This was quite confusing at times, but I found that drawing out and visualizing what I wanted made this easier.
### The Build
Then the fun part began! I started by setting up a basic terminal menu with the commands that I wanted to be available to the user. From there, I was able to work out which functions each class would require and distributed those methods to each class accordingly.
There were a few hiccups along the way while determining which classes would have access to the others’ functions but after a bit of troubleshooting and refactoring I had a fully functioning app.
Next step, was making the app visually appealing. As a creative, this part was the most enjoyable for me. I searched Ruby Gems and found really helpful gems such as Box Puts, Colorize, and TTY Prompt. Each of these gems allowed me to simplify the screens that the user would see so as not to take away from the app itself.
Finally, I discovered ASCII art. So I was able to find a beautiful example of a bookshelf and implement that on the startup page of the app. See below:
ASCII Bookshelf Art
## Bookshelf App Features
### Main Menu
The main menu of the app gives you the option to search for books, view your personal bookshelf, view the bookshelf menu, or exit the app.
### Search
The app allows a user to search Google Books for books by author, subject, title, or specifically the ISBN. There is a slider option (provided by the TTY Prompt gem) that will allow the user to select how many books they would like returned.
Search Slider
### Bookshelf
Each user will be assigned their own personal bookshelf. Upon opening the application they will be prompted to enter their first and last name which will be checked against the current users and either “logged in” to that user ID or creating a new one. This allows a specific bookshelf to be assigned to a specific person. With more time and education on creating log ins for an application, I would ideally add more criteria for the log in so as to avoid confusion for people with the same name. But for the purposes of this assignment, it works fine.
When selecting the Bookshelf option on the main menu you will either have a list of books that you have already saved returned to you or an error letting you know your bookshelf is empty.
Bookshelf
### Bookshelf Menu
This menu allows the user to either hop straight into the search function so as to add more books to their library or delete existing books in the bookshelf.
### Book Menu
This menu shows up after requesting more details from a specific book from a search. It gives you the option to view the books summary, get a link for the Google Books info page (specific to that book), save the book to your bookshelf, or return to the main menu.
Book Menu
## Conclusion
Ultimately, I found this project really enjoyable to work on. I learned so many new things such as API functionality, using different ruby gems, and ASCII art. I also got more experience error handling which I know will be very useful in future. I am proud of what I’ve made and I’m excited to dive more into Ruby in the next module with Ruby on Rails.