DEV Community

Cover image for Command Line Interface with Ruby Anyone?!
jCode319
jCode319

Posted on

Command Line Interface with Ruby Anyone?!

Week 4 aka Phase 1 Project Week was all about building a CLI (command-line interface) application with Ruby. I will admit, I was both excited and nervous at the idea of embarking on this journey. I was gradually increasing my Ruby skills and this would be my first test... no pressure.

The project consisted of using a website to extract info either via Scraping or using an API. We would need to scrape the data using Nokogiri and use that collection of information to put together a functional user interface. Our scrape also had to include a nested layer that would reveal additional information within the program. Lastly, this application needed to include quality object-oriented design patterns.

Leading up to project week, I was a little behind in the labs and was not picking up on some of the Classes/Instances material as I had hoped but I was determined to catch up and get through it by any means necessary. Lucky for me, I had awesome and talented cohort teammates who assisted me along the way and our instructor laid out a great framework for the project. In addition, we had an opportunity to see former students' projects which helped calm my nerves a bit.

Since part of the requirement was having some form of relationship between my classes I decided to do my project on cocktails because who doesn't like a yummy adult beverage!!! My relationship would include Technique/Method -< Cocktails: Technique has many Cocktails and Cocktails belongs to a Method/Technique. My first level scrape retrieved the cocktail name, drink making method / technique and a second url that would lead to the second scrape that gathered the description and ingredients for each cocktail.

Prior to writing code, I needed to pick a website to scrape so I browsed around looking for a website about cocktails that wouldn't be too difficult to scrape since the process was tedious and require a little trial and error. I settled on Liquor.com because the website was clean with a lot of repeating content/layout. The process of extracting info via Nokogiri was fairly easy; however, the trick came in trying to find the right formula for each category of info that I was looking for and ensuring I was in the right element tags. This is apart of the project where I got very familiar with binding.pry. This proved to be the answer to a lot of trial and error testing.

Now having completed this process, if I ever had to scrape a website, I would definitely know what to lookout for during my initial canvasing and avoid complicated sites. This would save countless hours scraping bogus sites and wasting precious time.

Once my scrapes were functional and providing the correct content that I looking for, I started pseudo coding the user interface which was a giant loop. This also provide an idea of what I wanted the program to do, which kept me on track. This wasn't the prettiest, but it worked! The relationships between the info really helped with the creation and organization of my classes and files.

For the sake of time, this application only has 1 technique - shaken cocktails; however, the OOP code makes it abstract enough that it would be able to adapt to additional techniques being filtered through the scraper class. The project was a rude awakening of facing fears and how to navigate through failure in order to achieve success. I learned a lot throughout this process and proud of my little simple cocktail_pedia application.

Cheers!

Top comments (0)