(Note: I'm moving my posts from my time at Flatiron School from my Github to this platform. This blog was first posted on December 10, 2019)
For our first big solo project at Flatiron we were tasked with creating a Command Line Interface application that scrapes data from an external source. My app, Games Coming Soon, gets information from IGDB.com on PC, Xbox One, PlayStation 4, and Nintendo Switch games coming soon. It allows the user to choose the platform and month for game releases, or see all upcoming game releases.
To make the app I used Nokogiri and Open URI to gather and parse data from the website and colorize to add some style to the output.
I created a Scraper
class with a class method to handle gathering information from each ‘coming soon’ page, and another to handle scraping info from an individual game page. The info is passed as a hash to a Game
class constructor that checks if the game already exists on another platform (since games can be on many platforms). If it exists, it adds the platform to the already existing game. Otherwise, it creates a new game instance.
There is a Platform
class to handle creating the different platforms and a ReleaseDate
class which creates instances for every new date a game is released. It provides methods to find games being released in a certain month or on a certain date. The ReleaseDate
class methods can be used with the Platform
class methods to find games released for a specific platform within a specified month.
The CLI
class keeps track of the current mode and the user’s menu choices. It consists of a main run
method that loops until the user quits by inputting whatever the quit number is on the menu they’re looking at. Each time the loop begins it runs a method called print_to_cli
which handles printing to the terminal for each mode. For example, when the app begins it is set to :platform_select
mode so print_to_cli
will run a method to print the menu that displays platform choices (Xbox, PS4, etc). Once the user makes a selection, the update
method runs and again, depending on what mode is currently set, runs methods pertaining to that mode. It will then update the mode and when the loop begins again it will print for that new mode. For example, once the user makes a platform selection the next mode set will be:month_select
. When the loop begins again it will print the :month_select
menu, where the user can select which month they’d like to see game releases for.
Highlights
I learned a lot from this project about scraping, formatting strings, using gems such as colorize, etc. I learned about the importance of using git branches to separate features when I spent 2 hours trying to implement something that ultimately didn’t work and was able to easily go back to my project’s state before I made a mess of it. I’m also deepening my grasp of object orientation. It’s one thing to work on the lessons and kind of get how it works, but it’s a whole different experience to write your own code and realize how objects relate to one another.
What’s Next?
My project works, which is great! However, towards the end it started getting messier than I’d like and it could definitely use some refactoring. I tried to give variables and methods descriptive names, but I still find myself forgetting what something means or does, so I’d love to go back over and clean it up when I have some free time.
Top comments (0)