CLI Project

 For my ruby CLI project for Flatiron, I decided to create a pokedex that would allow me to quickly find the location of any pokemon in the Let's Go Pikachu/Eevee games for Nintendo Switch.  


    All data is pulled from the table data on this site.  I will include screenshots below, but feel free to check out the site directly with your dev tools. 


Scraping the Site

This project's main gem dependence is Nokogiri, a web scraper gem for rails.  My scrape function is pretty straight forward.  I begin by initializing my pokemon objects with the three key points of information that I'm after: their names, numbers, and most importantly where they can be found within the game.

Afterwords I configure Nokogiri to go and open the url with the pokemon data on it and create an empty array object where I'll be pushing all the scraped data into to search through and filter.


Now when I inspect with dev tools and look at the data I want to scrape, I can see that it's stored in a table.  Since it's the only table in the HTML for this site, Nokogiri will know to grab it by the element label 'table' and I can save myself from typing out the entire name of the div.  

Each table row is labeled "tr" and contains 3 pieces of information nested within the cells of the table, therefore, each table row is its own pokemon object so we assign each cell to it's information and push it into the array.



Searching for pokemon

 

Now that the table is scraped and stored in the Pokemon array, I make the CLI facing search feature.  


Finally I make the loop condition where it will ask if the user wishes to search for another pokemon and let's them know their search results.


Conclusion

 Using Nokogiri was a pleasure and it will be a very useful tool for my future projects where I need to gather and organize lots of data.  This is what the user will see when the gem runs.  Note also that it will capitalize each search correctly and remove case sensitivity from the table. 


Comments