CLI Data Gem Portfolio Project

Rony M.
2 min readOct 15, 2020

After going through the first modules on Flatiron School’s Full Stack Software Engineering, it is time to put the skills on practice with my very first project with Object Oriented programming on Ruby.

For this project, I have to build a CLI application that retrieves data from a given website of interest and presents specific information from it, through an user interface shown in the local terminal.

The very first step consists on choosing a website (nyc.com, on my case). The idea is giving the clients a fast, straight forward application that allows them to navigate and explore the latest events in the city and their details.

Next, I had to choose the data retrieving method. It can be either through scraping or consuming an API. Although the second method seemed more appealing to me at first, I have felt more comfortable with scraping the web using the Nokogiri and Open-URI gems.

I have also included 2 other gems, which are Rake (for task running) and Colorize (to make a better looking command line application).

After setting up my environment, it was time to start coding. I’ve started by creating 2 classes (CLI and Scraper), along with the environment file and the executable “bin” file that would run the app. For each class I would define a certain amount of methods, which weren’t many on this case for being a simple application.

I also got to practice the use of class and instance variables, along with their methods. With an instance variable on a class, which is assigned with an @ symbol, we can store something common to that class without having sub-classes automatically also get them (and vice-versa). With class variables (assigned with @@), we have the convenience of not having to write “self.class” from an instance object, and we also get automatic sharing throughout the class hierarchy, when desirable.

Another important concept I have used during this process was the keyword “self”, which works as a reference to the current class object. It can be redundant on most times, while it also has several important uses, most of which are basically to distinguishing between instance methods, class methods, and variables. Everywhere else it’s useful when Ruby needs help distinguishing between method calls and local variables or local variable assignment.

Also, within instance methods self refers to the instance, within class methods it refers to the class, and it can always be used to distinguish from local variables.

After so many hours of building, researching and testing, I believe I have built what I wanted. Here’s a link to the project walkthrough: https://www.youtube.com/watch?v=iSVIu-HJjOM.

It was a good intro to OO programming, understanding how objects relate to each other and how they work together. During the progress, I felt like playing a puzzle where I created the pieces.

With 4 more projects ahead, I’m looking forward to study the next technologies and see what I can do with them.

--

--