Kittikoy, My CLI Journey

Nausheen Akhter
4 min readJan 7, 2021
Free-roaming cats are a wonderful part of the experience of living in Istanbul, Turkey

I am humbled and excited to have reached this far in Flatiron’s Software Engineering Program. This has been a completely new learning experience for me and one of the steepest learning curves. I am becoming comfortable with encountering the challenges of each lab and the process of research and problem solving each one requires. It really is a new way of thinking, not just a new language but a way to approach knowledge acquisition.

At the end of my Command Line Interface (CLI) project now, many of the concepts I was learning in the lessons have come together. Gems are amazing tools that allow us to benefit from the contributions of other developers as we create our own applications. Publicly available information in Application Programming Interfaces (APIs) are also incredibly helpful. It was intimidating at first to look at one, especially considering I would have to somehow pull some parts of that information into my own program — without copy & paste! The RestClient and JSON.parse methods made it so easy to incorporate this dynamic information.

My project, cats.cli, allows users to learn about various cat breeds at a fictional organization called Kittikoy and to select a cat type to adopt. Because my family loves cats and I recently moved to Istanbul — a city of cats — I wanted to incorporate our feline friends into my project. I was happy to find an API with the information I would need to create it.

What an API endpoint looks like

Istanbul is filled with cats. They live freely in the streets and both the government and average citizens feed them. Injured cats are treated and returned. The cats are friendly and full of personality, making every walking experience interesting and a bit comical. People can and do just pick them up and keep them as pets also. We have many cats visit our garden throughout the day and we get to feed and play with them. My son loves this new kind of life immersed among cats. He has bonded with several of them and really enjoys holding them. It has helped him through the difficult times brought on by COVID-related restrictions. This project honors both our new environment and my son’s experiences. “Koy” means village in Turkish so the organization’s name means Cat Village. The application gives users access to a list of cat breeds and allows them to learn more about one breed’s origins, descriptions, and temperaments. Then, the user can choose to adopt the cat of that breed or learn more about another breed.

Developing the CLI class was the most interesting part of this project. Creating even this simple interaction between the user and the program was very exciting. I finally got to see the utility of the various methods we have learned. After being stuck way too long with an error message, I learned the value of the .capitalize method in converting user input into a form the application could recognize. Simple but so important for functionality. Then I discovered that .capitalize makes all but the first letter of the first word of input lower case. This was a problem for the Russian Blue breed my son wanted to learn more about! Some pair programming with my classmates led to a final solution using .split, .capitalize, and .join. Here’s what it looks like:

def cat_selectionputs " "puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"puts "Select a cat to find out our more! For example, you can enter: Cyprus"puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"puts "Enter the cat name:"selection = user_input.split(" ").map {|word| word.capitalize }.join(" ")cat = Cat.find_cat(selection)cat_details(cat)end

I also used some simple metaprogramming to retrieve some of the data from the API. The two lines of code here eliminate the need for manually setting up attribute variables and avoid possible errors. Here, the program will iterate over the key-value pairs in the API hashes and retrieve the pairs when k matches any of the attributes I want.

attr_accessor :name, :temperament, :origin, :descriptiondef initialize(cat_hash)cat_hash.each do |k, v|self.send("#{k}=",v) if self.respond_to?("#{k}=")endsaveend

I learned how to call methods within other methods and methods within themselves. Another important concept was the control flow. Because users can input various answers, it is crucial for the program to have a set of methods ready to respond to those answers, especially to make sure the user is never left with just an error message or kicked out of the application unexpectedly. User experience is ultimately the most important component. If someone cannot use it successfully, they will not come back. To work through all the big and small errors and to finally have a simple application run successfully brings such a feeling of accomplishment. I am humbly excited to continue on this journey.

--

--