Your_Diaper_Bag, My First Project!

Ryan Locascio
3 min readJan 29, 2021

Your_Diaper_Bag is a gem that lists 16 items that would be found in a diaper bag. The user selects a number beside the item to show its price. This project was inspired by having a new baby about 5 months ago. I thought it would be great to have a gem that displayed some necessities for having a baby.

The gems information came from scraping a website for products and prices. I scraped “motherearthbaby.com”. I scraped the website with a gem from ruby called Nokogiri. Nokogiri makes reading XML and HTML much easier. It puts the parsed information into nested objects which make them easier to work with. Using this gem helped me pull the exact information I needed for my project.

In order to get the exact information need for my gem I used css selectors. I obtained these selectors by inspecting the page. I did this by highlighting all of the items I wanted to include in the my program on the web page. Then by right clicking the mouse and clicking on inspect pulled up the websites HTML. This helped me find the selectors I needed to grab the right information. After parsing and iteration I was able to pick out just the brand and the item price.

Another concept that I had to really grasp for this project and in learning the Ruby programming language is self. Self is a variable that helps us know the object that is responsible for the currently running code. Self also helps us define class-level methods, which can be called on the class such as this self.all method:

calling this self.all method on my class Item will return me an array of all the objects in this class. This method makes my future code much more organized and precise when I call it in other methods I need to manipulate the object I am working with.

I use this class method .all in this list_brands method:

Using this .all method allows me to take all of those class objects, iterate through the objects using .each and “puts” the brand to show my user in the command line what brands are available in their diaper bag.

What a journey it was completing my first portfolio project. So many headaches and doubts of if I could actually do this. And do I really understand the concepts I just coded into my text editor. Or was I just posing my way through Flatirons curriculum. I slowly learned that I do understand what I was writing. Through much trial and error, strife and stress I figured out that I do know how to scrape a website and iterate through that data to output what I need in a command line for a user to interface with.

--

--