Chris Houghton
3 min readJan 8, 2021

--

Command Line Interface Coding Project & Starting to Understand

I recently just finished a Command Line Interface program while going through the Flatiron School Online Software Engineering program. The project requirements were to find some sort of problem or information you could solve or use and writing code using Ruby, develop a simple application with a text based user interface.

The application I chose to develop allowed the user to input a Band/Artist they enjoy, think your favorite band. Input said favorite band and bing, bang, boom…bam! The application finds 10 more bands in the same genre or similarity to your favorite or any band you selected.

To go one step deeper the user can then select any band in the list of 10 similar bands and receive a little bit of information like band history, albums, genre of music and a list of members.

To begin the coding and app blueprint we used the Bundler gem to create an ‘scaffold directory’ with all the files we will need for the application. We begin by writing bundle gem <our gemfile name> which creates a local git repository if we have git installed. We then choose if we want a license and code of conduct file for contributors. It includes a bin, lib, and spec file for writing our classes and code, the command line interface and a test for our code if we choose to.

The App then utilizes the Ruby Nokogiri & Open-uri Gems which scrape whatever website you choose for information you select in the html. One of the issues I ran into here was if the website I was “scraping” for information didn’t have the information we expected or happened to be in a slightly different location I would receive an error. I chose to continue with the Nokogiri Gem as that is what i started with and write in a rescue method that saved the program, allowing it to continue on scraping different locations until either the info was available or we couldn’t find what were looking for in which case we receive a message letting the user know the info was not available. My curiosity and what Im inclined to believe is if an API call would have solved this, something I will be looking into upon refactoring the code (simplifying/abstracting the code for a cleaner, smarter, and easier to read experience).

I built this app using the error rescue methods, the scraping with Nokogiri, the different Classes and objects, and the actual interface which I’ve name ‘No More F.M.’. The part I enjoy the most about coding is the interaction between the methods and the data,

I really like this:

self.all.select{|record| record.album_name if record.artist.name == artist}.map{|record| record.album_name}

Here is a method that selects an Artist’s Albums based on the Artists name both of which are objects that have been created, and associated through certain attributes. What I like about this method is it doesn’t stink. It’s explicit, searching for and ‘select’ing items based on a specific attribute first before ‘iterating’ over the ‘select’ed attributes and displaying them for the user. When I think about the code I think I want this data to go here, I want it manipulated or read, I want to then send it there or retrieve it here. I think about it like water in pipes going through certain valves and routed, heated and cooled, manipulated and finally presented in our desired form. To do this we write our different classes for the objects we want to create, methods to access them, and a CLI to display and get input from a user.

From there we commit and push to githhub. All in all it was difficult but enjoyable experience, I gained insight and the next time will be deeper, easier and more refined. Utilizing everything I’ve learned so far, it was hard but not in a way that seemed like work but rather a “challenge accepted” sorta way. Writing code, breaking the program, researching, fixing, smiling, and repeating. Learning and progressing towards something I thought was just a dream for a very long time.

--

--