Greatest Films: The CLI Data Gem

Posted by Alex Zdatny on January 22, 2018

Since October, I had been struggling with the CLI Data Gem project and all of its components. When I was brainstorming ideas for what to do, I knew I wanted to do something involving films. Scrapping data from a list of films specifically related to genres or a “greatest” ranking seemed ideal. It was something I could have fun doing, but also learn vigorously along the way. I was very excited to figure out the process of scrapping data from a website and combining it with what I learned in the lessons and labs. However, it was a lot more to digest than I thought and it became one of the greatest challenges in my coding journey so far. My issues with this project arose from the hiatus I had taken after finishing a majority of the Object-Orientation unit. I had been progressing through the material at a reasonable place during the first three months at the Flat Iron. There were times I would spend at least eight hours a day studying and experimenting with the concepts and methods. But then I hit a roadblock mentally where it was overwhelming to code. The passion that I had was nearly gone. This roadblock that I hit taught me a lot about myself. It tested my time management skills, organizational skills, as well as refreshing my mind with the content I had learned.

Originally, I chose AMC Filmsite’s 100 Greatest Films of all time, as a list to scrape the data from. I watched Avi’s walkthrough of the CLI Data Gem and started writing the code. During the next few days, I tried to plan out the steps for the project including the class and instance methods for each lib file and the user menu in detail. Initially, I was off to a good start, but then I entered a perplexing sate. Every time I would try and test the code with binding.pry, whether it was for the attributes the user has access to, or just the general menu they go through, errors would appear consistently. The requirements for the project didn’t really seem daunting, but it felt like the first real chapter into the world of coding. My plan was to scrape data for each individual film in the list, but the site’s code was too convoluted to use, especially for my first portfolio project. I made far too much a challenge spending hours trying to code the CLI, Scraper, and film classes that everything would clash. It became incredibly frustrating to the point where despite finding the material compelling, it was intimidating. I started to question whether development was the right track and a test of my ambitions. So I decided to take a break from code and concluded that it was something I couldn’t do alone. I wasn’t asking for help because I was intrigued with challenging myself and wanting to figure out everything on my own. It was also something I experienced in the past while working on some of the labs in Object-Orientation Ruby. This contributed greatly to me not making progress with the project.

After a few weeks of struggling with the project, I scheduled a session with one of the technical advisors to go over the code and evaluate the errors to see how to conquer this. He said that I had overworked myself and it was much better to choose an easier site to scrape data from. He walked me through a little bit of the setup and I had more confidence this time around. I eventually chose Rotten Tomatoes Greatest Comedies, which was something I should have done in the very beginning. It was also in the realm of film lists, but the process was much calmer than before. Errors started to make sense as well as the layout of each class. I looked back at all of the labs and lessons that I completed in object-orientation Ruby. Creating each class from scratch became more familiar and I formatted the data into a smaller scale that would cover the first ten rather than the whole list of films. I decided what attributes the user would be able to view for each film that they selected and expanded into each class of the project. For example in the scraper class, after selecting the link for the attributes from the index page, I used the slice method so that the user would see the top ten films from the list of 100.

Writing the code for the start and menu methods in the CLI class was a pretty smooth process. The CLI Class was essentially the foundation of the data gem so once I established how the user could access the data; all I needed was to connect the scraper and comedy classes. However, I kept receiving errors because of the Scraper class where it was still not scrapping the list from the index page. In fact, it had jumped over the instance method I created detailing which part to scrape from. As I mentioned earlier, there were some places in the code that I couldn’t comprehend for why they weren’t working properly. When I tested again with binding.pry in the terminal for the object methods, it would sometimes not take the user through the entire menu. Though after meeting with another technical advisor, I fixed this issue. Reading errors and why they occur is definitely something I want to improve on so that I don’t spend hours recirculating the same code.

Eventually, I was able to correct the errors so that the user would be able to view the film’s attributes. Writing the objects for the film’s attributes within the comedy class became more of lengthy process. I wanted the user to have access to the summary, director, cast members, and various reviews for each film provided on the links from the index page. It became extremely helpful to look back at my notes from the HTML and CSS unit as they provided div setters for the elements I scrapped from the site’s code. Once I coded the final details of the scraper class, this lead to a more interesting challenge. Depending on what attribute the user would be searching for, each element in the comedy class had to have a different instance method. I played around with setters and readers until I organized the attributes specifically from the index page such as the title and rating into the attr_accesor method.

For the menu provided in the cli class, users have the ability to:

  1. Select a film of their choosing
  2. View the film’s attributes and details
  3. Decide whether they want to make a new selection from the drawing board.

If they choose not to explore another film, they will type ‘exit’ in the panel and the goodbye message will appear saying “Thank you for visiting Rotten Tomatoes Greatest Comedies. Goodbye!”

Overall, structuring the greatest_films files was more difficult than I expected, but it taught me some important lessons. Object-Orientation Ruby is a unit that took a lot of time to digest because of all of the detailed concepts. Spending time with each concept efficiently would have helped a lot more than facing it all at once. When it comes to my next portfolio project, I want to be more organized, prepared, and assertive. The CLI Data Gem was both a major learning and creative experience as it tested my knowledge and coding skills. I suppose it also took this long because even in moments where I would receive errors, I spent so much time retracing my steps. I kept going back and forth whether it was GreatestFilms::Scraper.new_scrape_film_index or GreatestFilms::Scraper.new_make_comedies for the starting method in the CLI class. For the amount of time that I’ve spent on this project, it will definitely drive me to be a lot more engaged and motivated moving forward.