After just two weeks of studying at Flatiron School (Software Engineering Immersive Program), we were given the task of creating our first project — a CLI app. We could choose to build either a Data Analytics Project or Command Line CRUD App. My partner and I chose to build a CLI CRUD app, called The Bookshelf.
Our project helps users keep track of books they would like to read. I often have books recommended to me by friends, or hear about an interesting sounding book in a blog, on Instagram or elsewhere online, and I think; “yeah, I’m going to read it one day…”, but by the time I get around to downloading new books I have forgotten the books’ title and spend hours browsing through the library to find a good book to read. Our app helps with that. Now all the books I want to read can be kept on my virtual bookshelf.
The interface of the app is very simple. The app greets the user and asks for their name. If their name already exists in the database, the app pulls up their bookshelf, if their name is new to the program, a new empty bookshelf is created and the user can start adding books to their collection.
The app has full CRUD functionality, a user can add books, remove books from their shelf and search books by author or by genre. Also the user is able to clear their bookshelf entirely and start a new collection.
We used three models for this project: a bookshelf, a book and a genre. At the beginning it was quite confusing to figure out how the models relate to each other, our Active Record methods wouldn’t work because of wrong associations, but once we fixed the relationships between the models we were able to make our program work. For me, the main takeaway from building this project was learning the power of Active Record. Spend some time researching its methods and then you will be able to use its magic. For example, instead of writing seven lines of code you can write just one and make your code look more clean and elegant.
Three ways to make your CLI app pretty
- It is hard to make a CLI app look cool, but my inner designer would not let me submit our app as it was. After thorough research, I stumbled upon the TTY Prompt gem which allows you to improve your command line app’s interface. It is very easy to install and very easy to use. Now our main menu looks pretty cool, and a user can navigate up and down the menu with arrow keys and confirm their choice by pressing Enter. https://github.com/piotrmurach/tty-prompt
- Also, we used the Colorize Gem to make our text stand out on the screen, this gem is super easy to use — you just chain a color name to a string. https://rubygems.org/gems/colorize/versions/0.8.1
- ASCII Text Generator allows you to generate text and select a cool font from their collection. Don’t miss the opportunity to add a title to your app! You can play with fonts here http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20
I am very happy that Flatiron made us build our first project after just two weeks of studying. I feel like it doesn’t matter how many labs you’ve solved or how many lectures you’ve sat through, you won’t be able to learn things until you start building them from scratch.
For a short video demo feel free to head over to my Github page. https://github.com/rita-morozova/Virtual-Bookshelf-CLI-