Skip to content

Instantly share code, notes, and snippets.

@aviflombaum
Created October 5, 2017 22:02
Show Gist options
  • Save aviflombaum/53527453f246292639146945df3eca30 to your computer and use it in GitHub Desktop.
Save aviflombaum/53527453f246292639146945df3eca30 to your computer and use it in GitHub Desktop.
class GenreScraper
def initialize(genre_url)
@genre_url = genre_url
end
def scrape
data = # scrape logic
data.each do |movie_info|
Movie.new(movie_info) # pass the raw data to a movie class to store
end
end
end
class Movie
@@all = []
def initialize(info)
@info = info
@@all << self
end
def scrape_detail
# @info[:url] or @url contains the url of this movie's page
movie_details = # scrape logic
@director = movie_details[:director] # filling in the details for this movie
end
def self.find_by_genre(genre)
@@all.select{|m| m.genre == genre}
end
end
# enter a genre
genre_input
genre_scraper = GenreScraper.new(genre_input)
Movie.find_by_genre(genre_input).each do |movie|
puts movie.title
end
# select a movie
movie_title
movie = Movie.find_by_title(movie_title)
movie.scrape_detail # kick off the detail scrape
puts movie.director # now that instance is further populated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment