GymFinder: My very first CLI gem

The planning, the development, and the most epic facepalm-inducing bug of all time

Zeshan Raja
4 min readJun 10, 2020

As a student at the Flatiron bootcamp self-paced Fullstack Web Development program, I was recently given my first project: to create something from scratch. It was quite daunting at first. During the lessons leading up to the project, the repositories are already made for you along with the necessary gems already installed. Until now, I’ve taken all of that for granted.

Sure, I wasn’t expected to create the new Google, but simply create a command line interface that displayed data once a user chose an option from a list that my CLI provided. As someone who has a healthy obsession with health and fitness(see what I did there?), I naturally gravitated towards a CLI that eliminated excuses to not hit the gym: GymFinder.

The planning stage wasn’t very extensive primarily because I only had to go one level deep. So to achieve this, I just had to scrape data in one class, instantiate that data in an another, and display in it my CLI class.

As someone who has limited experience with git, navigating around the basic commands took some getting used to, but once I took the chance to actually understand git commands, I caught on pretty quickly.

At its inception, I debated whether to use an API or to scrape via nokogiri. I primarily thought of whichever option would be less frustrating, and since scraping was a concept that was a lot fresher than using an API, I’ve decided to go with that. I found pages on both yelp and google maps that were perfect. They had addresses, phone numbers, and testimonials, all of which I needed. However, I kept on getting a 503 (OpenURI::HTTPError). After some intense googling, I realized that the enabled Javascript on chrome meant I had to use the watir gem. Not that I’m opposed to leaving my comfort zone, but since this was my first project and I had a lot riding on this, taking the paths of least resistance seemed wise. To that end, I chose to scrape a site where enabled Javascript was of little consequence.

I also took this opportunity to learn how to write my own RSpec tests, and boy did it feel powerful! It took some trial and error and although it’s pretty basic, it was great to get my feet wet with something I’ve wanted to learn for a while. One thing that I would like to remember next time is that I should ideally write my tests before or alongside my classes. I actually wrote out most of a class and then had the idea of writing my own tests.

When learning something new, it is totally normal to make mistakes. In fact, I would argue that it is necessary. Mistakes are a pivotal part of growing and developing, in tech and otherwise. But no mistake is as pervasive as a non-mistake. I created a bin file as an executable that required my environment where I then required all the other classes and gems, mainly pry and nokogiri. During development, I wanted to test out methods in my scraper, so I ran it through lib (where all the relevant files live), and to my surprise, the terminal outputted a NameError for nokogiri and a NoMethodError for pry. This was Friday. I kid you not, I spent the ENTIRE WEEKEND going over the instructional how-to videos and github repositories of the demo projects with a fine-tooth comb. I pestered the two project leads to the point where I was starting to feel badly. I read my gemspec, gemfile, and environment, line-by-line, looking for what was causing those errors. I read every stackover flow post about requiring gems I could get my hand on. It wasn’t until Monday morning where I realized that my code was fine; I just had to run my CLI through my bin where all the gems were required. I did that. It ran fine.

*Deep, long sigh**facepalm**whimper*

When I achieved core functionality, I decided to go over what I had and refactor. I realized my scraper method used .each where .map not only would have sufficed, but eliminated the need for about five lines of code. I often fall victim to over-ambition, so I intend to manage that properly moving forward.My biggest takeaway is to avoid the crippling pitfall of overthinking.

Note to self (ha, OOP humor): Breathe, tackle a big task in little chunks, and realize that sometimes that a bug you can’t seem to find may be right in front of you, if it even exists at all.

--

--

Zeshan Raja

A beginner student of programming, a beginner student of life, a beginner at pretty much everything.