On Beverly Hillbillies & Clis

February 22, 2017

Come and listen to a story ‘bout a gal named Trace
Poor gal’s code was all over the damn place
Then one day the dang lightbulb flickered on,
And up through the haze — well her CLI was done!
(gem that is, AustinCrime, Texas Rubyista)

Life likes to happen while you’re learning. It doesn’t care that you’re at a pivotal point of your coding career and heading into your very first portfolio project. Life says, “Kiss grits! And make sure to add lotsa butter…”

So. The Flatiron CLI project is a web scraping project. I decided to do my project using OpenData from data.austintexas.gov. I did not know at the time that I was one of a small group of students to ever use an API for this particular project!

Right after I started figuring out how the API worked and started getting my gem setup, life happened. Right after I had a nice framework.


I came back five weeks later barely knowing what was going on. And got so frustrated I scrapped EVERYTHING. Deleted the github repo and everything. After some talking to from my #NerdyNeighbors, I dusted myself off and tried again.

And boy, did I catch a groove!

As I said earlier, I decided to “scrape” an API and used HTTParty to help me accomplish it. It works like this: You get a list of crime types, pick one, see a list of crimes. Everything was going great until I kep returning all of this white space:

Here’s what caused it:

I had nested loops. Using .collect. On hashes. I didn’t know it wasn’t good practice to do that. A group of the NerdyNeighbors (I really do have a great group of people supporting me — they jumped in without me ever asking) jumped in to figure out what was going on.

Here’s what fixed it:

We narrowed it down to the whitespaces being the equivalent to arrays of nil. In order to get rid of them we chained a reject {|element| element == nil} to the end of the first (outer) loop. That did it. I still have an issue with instance and class variables, but that’s a post of its own. But you know what? I made a gem. A friggin’ gem. Take that!


https://rubygems.org/gems/austin_crime if you’re so inclined :-)

Well now it’s time to say goodbye to CLI and its gem
They would like to thank you folks for kindly dropping in
You’re all invited back again to this locality
To have a heaping helping of their hospitality

comments powered by Disqus