CLI data gem project

I am revisiting an earlier attempt at the CLI data gem project. I went through Avi's related video carefully and feel l understand what we are doing here and how useful creating our own gems can be. The idea of my gem is to create a handy list of upcoming movies that will be released in theaters for movie fans interested in what films are on the horizon. 

In this project I've added pry and nokogiri to the gemspec so we can get website data in the terminal. Pry is an irb alternate that lets us browse source code and documents. And Nokogiri is a very helpful HTML parser so we can access pieces of an html page to use in our Ruby code.

My upcoming-movies rb file in my library folder requires Pry, Nokogiri and Open-Uri as well. Open-uri allows us to open a website as a file. I don't feel too familiar with this but hope to learn more about how it works in the future. We also require-relative the three ruby pages in my library>upcoming-movies folder. We use the a version.rb to keep track of our own versioning. Most of the code for the project is in the cli.rb and movies.rb files. It was great seeing Avi think through the logic for what we want the command line interface to do. I find it intimidating to write code from scratch still. I went through this carefully and reviewed a few procedural Ruby lessons but do need to think through a bit more how these two files work together. Some of the language feels abstract to me still.  

In the movies.rb file we set up attr_accessor (read/write) variables for all the things about an upcoming movie release we would like to display. I switched around a few of the options because I started with looking at the Box Office Mojo site list and the IMDB upcoming list was easier to scrape and did not have a large messy table to contend with. Not sure why we need both a and self.scrape_movies.  I think it's because the today method stands for what we are doing and the scrape method is more the information itself that we push upwards to the today method. In the scrape_movies method we create an array of movies, shovel in information from the scrape_imdb and return this information. The last method is the self.scrape_imdb. We have a doc variable which connects us to an imdb page with help from Nokogiri. We create a new movie and use and list where and how we find movie names, dates, genre by scraping the imdb website. 

For me, scraping itself was the hardest part of the assignment. I definitely did some trial and error in searches to isolate information on what is a fairly complex live internet page. With a point in the right direction, the bottom bar in the Javascript console helps visualize the DOM path. One thing I ran into was a needing to point upwards to grab a few things like date and genre. Also found that I had oftentimes multiple genres to contend with, between one and three so one couldn't just call the first then the second or something as a straight list and still hope the connect to the movie titles which could be listed more linearly. I discovered you can call a "span:nth-child(1)" so you could access the first genre listed, etc. I also found out you can look at which movie on this updating movie page by referring to its array number. See image especially the last lines!  












One things was interesting to be was that what I scraped in Nokogiri didn't quite match up to what would display if I ran ./bin/upcoming-movies to see the final output. Not sure why this is. I had the best luck in terminal if I referred to each variable with an array number.

The cli.rb file has more connection to the actual operation of the CLI. We're adding the info from the upcoming-movies.rb file here via The call method is currently a container for the other method. list_movies has an each.with_index which has two parameters the second is a number so we can have a numbered list of returns. I added an array to return 7 results but have managed to return the first movie seven times! Need a tiny bit of help to wire this to return not just the movie # + date, length, etc. but also multiple movies in order.  The next method asks us if we want to hear about any of the movies and prints the related movie description if we press a movie number. If there's no typed input we put to the terminal 'enter the movie you would like to hear about' and if the input is more than zero we put the proper movie description. We have an eslif that that if you enter 'list' we can return the original list of movies again. We have a message for an input we don't recognize and a goodbye message if you type exit to leave. This is the project process currently:

Screen Shot 2016-09-02 at 7.22.14 PM.png


Things I would be interested in working on:
1 - how to call multiple span:nth-child(1). Is there a better way than just a list here?  
2 - putting a variable into the arrays so I can display multiple movies. An array for a group of arrays?

lib>upcoming releases>cli.rb
3 - strange . after the
4 - fixing the menu method in cli.rb so you only enter a number between 1-7.  
5 - hook up entering 'list' at the end of a movie description so someone can return to the beginning after reading a description.  
6 - Add a note to tell people you need to type 'exit' to quit and detach it from the bad input message.  
7 - The menu method feels messy in general. is there a way to simplify and clean up after changes have been made?  

video Block
Double-click here to add a video by URL or embed code. Learn more.


What else could be added:
A longer list of titles
The director, stars and rating from the page I'm scraping
Open a browser to the imdb page for the movie if someone wanted
List related upcoming titles by genre?
List previous movies by director?