My First Ruby CLI Data Project
“All things are difficult before they are easy.” — Thomas Fuller
Working on a project from scratch on your own can be scary for code newbies. But once you’ve gone through the whole process step by step, corrected every error you’ve encountered, refactored your codes by delegating the responsibility to the appropriate class, you would realize how rewarding the project is.
An Introduction on my CLI data project
My CLI project allows the user to choose one Pokémon from a list to view some basic info fetched from an selected API. The user can also get a list of all the Pokémon he or she has checked.
I’ve created three class objects. The Api class is responsible for fetching all the data needed from a given API. I’ve written a class method to get a name list from the API index page. The return value of this method is an array. I’ve assigned this value to the Cli class variable @@topics. I’ve also written an instance method to handle every single Pokémon’s data. The fecth_pokemon instance method will get me a return value of a hash. The hash is to be used as the argument to be passed into the Pokemon. new() method.

The Pokemon class is responsible for instantiating every Pokémon instance and save it to a class variable @@all. To avoid any possible duplicate instances, I’ve created the class method find_or_create_by_query. This method is called upon the user’s query to find any existing Pokemon or create a new Pokemon instance.
The CLI class is responsible for guiding the user’s action and get the user’s input.
Make the Cli More Visual

Making the Cli application more visual not only helps enhance the user’s experience, but also encourages to explore as many gems as I could.
In this project, I’ve used the ‘colorize’ gem to set various text colors. I’ve also created a logo art by applying the ASCII text art. I found this article really helpful for me to add a picture logo to my project.
Lessons I’ve Learned from Project101
(1) Plan the project and imagine the interface before coding.
(2) Start with the structure.
(3) Use pry. Learn how to read error messages.
(4) Work on your local environment instead of IDE. Try to get familiar with git and GitHub asap.
What I Missed in This Project
I didn’t explore much on the relationship between the objects. If I have time to refactor this project in the future, I will create a trainer class object and practice setting up a #has_many method and a #belongs_to method. I would gain a deeper understanding of deciding which side of the relationship should be the single source of truth then.