CLI Project

Posted by chaimoosh on February 22, 2018

So, as the project started, I was looking for a website that would meet the requirements of what needed to be done. I was looking for something that I could scrape data from and then take it to the next level and give some info about it. I also wanted something that interests me. So I figured I would go with something historic, because I enjoy learning about history. I also was looking for a website that would fit the details of what needed to be done for the assignment and wouldn’t get to complicated.

I started the lab by watching the video of Avi doing the CLI gem. After watching that, I got the idea of doing the Seven Wonders of the ancient world. I thought it would be a good idea because I could scrape data from the website to fulfill the requirements of the lab, and then scrape another level to get the information about them. At that point, I started to look for a website that listed them in a format that I would be able to scrape them properly. I found one website that seemed like it would work and started to work on actually programming the gem.

The next thing I did, was try to get it started; so I went back to the video of the CLI to see how to use bundler. I watched what he did and used some of the references he gave to set up the gem properly. After one ot two tries, I got it to work and was ready to start coding. I started by just putting the files that I wanted in the bin file, and worked backwards from there. I got that to work and made some test code just to see if it could do what I wanted. When it did, I was ready to start scraping and actually sending the right data to the CLI.

Then I was ready to start scraping the website. I tried to scrape the website I had found originally but it just wasn’t working properly. I tried to debug by using pry, and I realized that even though on the surface it looked like scraping this website for the Seven Wonders could work, I quickly saw it couldnt be done. They were in the same format and they didnt all have the same CSS class names, so I couldn’t scrape it. It was frustrating to find this, because that meant I would have to find a new website, but I knew that I would be able to find it the right way somewhere else. I googled it, and found a website that actually had them all in seperate DIVs, and with the same class names for the Wonders and the info about them so it was perfect. I put this into my scraper class and it worked perfectly. My scraper took the information from the website and put into an array of hashes that had name and info on each one of the Seven Wonders. The next step was to take this giant array and turn all these hashes into objects, so they could all be seperated and worked with. To accomplish this, I made another class that would take care of this, and make every one of the Seven Wonders into an instance of a class, each one with it’s own name and info so it could be referenced again. At that point I was ready to take what I had put in the Wonder class and bring it to the CLI class and see if it would work. I did this, and shockingly it worked pretty quickly. I was able to greet the user display a list of the Seven Wonders, and if the user would select the number of any of the wonders, it returned the information about it. This was all great, but there was one problem; instead of displaying the list of the Seven Wonders once, it was displaying them twice, and numbering them twice. Every time I would ask the CLI to display it again, instead of putting the original numbers, it just kept counting. I couldn’t figure out how to change it, so I tried a few different things in my code and then I realized that when I was calling what was supposed to be my array of instances of the wonder class, it was creating new instances, so I had to figure out how to change that.

I had reserved a meeting with one of the tech coaches to go over my code, and thankfully it was when I was stuck on this issue that it happened. He showed me how to change it that it wouldn’t create new instances constantly and instead just call on the array. After we got this to work, my CLI was up and running. It was the best feeling getting it to finally work.