Class: BestMovies::Movie
- Inherits:
-
Object
- Object
- BestMovies::Movie
- Defined in:
- lib/best_movie_year/movie.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .create(movie_array) ⇒ Object
- .reset_all ⇒ Object
- .scrape_desc(url) ⇒ Object
- .scrape_movies(main_url) ⇒ Object
Instance Method Summary collapse
-
#initialize(title = nil, desc = nil, url = nil) ⇒ Movie
constructor
A new instance of Movie.
Constructor Details
#initialize(title = nil, desc = nil, url = nil) ⇒ Movie
Returns a new instance of Movie.
6 7 8 9 10 11 |
# File 'lib/best_movie_year/movie.rb', line 6 def initialize(title = nil, desc = nil, url = nil) @title = title @desc = desc @url = url @@all << self end |
Instance Attribute Details
#desc ⇒ Object
Returns the value of attribute desc.
2 3 4 |
# File 'lib/best_movie_year/movie.rb', line 2 def desc @desc end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/best_movie_year/movie.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/best_movie_year/movie.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
17 18 19 |
# File 'lib/best_movie_year/movie.rb', line 17 def self.all @@all end |
.create(movie_array) ⇒ Object
13 14 15 |
# File 'lib/best_movie_year/movie.rb', line 13 def self.create(movie_array) movie_array.each { |movie_hash| @movie = self.new(movie_hash) } end |
.reset_all ⇒ Object
21 22 23 |
# File 'lib/best_movie_year/movie.rb', line 21 def self.reset_all @@all.clear end |
.scrape_desc(url) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/best_movie_year/movie.rb', line 25 def self.scrape_desc(url) titles = {} doc = Nokogiri::HTML(open(url)) titles[:desc] = doc.css("div#movieSynopsis.movie_synopsis.clamp.clamp-6").text.strip titles end |
.scrape_movies(main_url) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/best_movie_year/movie.rb', line 33 def self.scrape_movies(main_url) movie_list = [] doc = Nokogiri::HTML(open("#{main_url}")) movies = doc.css("table.table a.unstyled.articleLink") movies.each { |movie| movie_title = movie.text.split(" ").first(11).drop(1) movie_url = "https://www.rottentomatoes.com" + movie.attribute("href").value movie_desc = self.scrape_desc("#{movie_url}") movie_list << { title: movie_title[0], url: movie_url, desc: movie_desc } } movie_list end |