Cats of Studio Ghibli: A Ruby CLI Gem
I have always been a huge fan of the Japanese illustrator and director Hayao Miyazaki. He has made many beloved films such as Spirited Away, Howl’s Moving Castle, My Neighbor Totoro and Kiki’s Delivery Service to name a few. For my first CLI Ruby gem, I thought it would be a lot of fun to use the public Studio Ghibli API to display all of the cat characters in the Studio Ghibli universe, and then allow a user to interact with them in different ways.
What Will Your App Allow A User to Do?
The app allows a user to view all the cat characters from the database found at this Studio Ghibli API link.
The app will then provide a list of options for the user to choose from. A user can view all the cat characters in list form by name, and then select a particular cat to view their details such as age, gender, eye and hair colors, and which films they appeared in. Then the user can go an additional level deep by following the prompts.
The best part of the app, in my opinion is that it returns all the best quotes from each cat! The user chooses “See Favorite Quotes” and bam! they get see Jiji say, “ You’d think they’d never seen a girl and a cat on a broomstick before.”
Steps I Followed To Create This Gem:
The first thing I did was set up my directory. I created two folders: “config” and “models”. In config I created an environment file and a seeds file. Then in models I created cat.rb, cli.rb, ghibliapi.rb, quotes.rb and then finally a run.rb file. In order to follow good object orientation design principals, I created several different classes that each had their own job and I tried to keep their functionality relatively narrow.
The most challenging part of creating this app was pulling the specific data I needed from the Studio Ghibli API. The studio Ghibli API lists the cat characters under “species”, and then for some reason, under “people” so it took a bit of finagling to get that part right. I used HTTParty to access the specific end point I needed.
The main job of the Cat class is to create a “cat” object for all all the specific instances of “cat” in the API. I assigned them instance variables of @name, @gender, @age, @eye color, @hair color, and @films. I also created methods to find a cat by name, print the details of each cat, and assign famous quotes to each cat.
The CLI Controller:
The CLI controller is where I defined what options a user interacting with the app will have. I wanted the user to be able to select from a list of options so I used TTYPrompt to enable this functionality. I essentially created a loop where you can enter the app and then exit the app based on what options you select.
Lastly, the Quotes class is where I simply assigned specific quotes, located in the seeds folder, to specific instances of each cat.
This app was tons of fun to create and I hope you enjoy it as much as I do. To view the code and download Cats of Studio Ghibli please visit https://github.com/kristinponsonby/cats-of-studio-ghibli
Thanks for stopping by!