Class: TopMovies::Movie

Inherits:
Object
  • Object
show all
Defined in:
lib/top_movies/movie.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/top_movies/movie.rb', line 2

def name
  @name
end

#siteObject

Returns the value of attribute site.



2
3
4
# File 'lib/top_movies/movie.rb', line 2

def site
  @site
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/top_movies/movie.rb', line 2

def url
  @url
end

#yearObject

Returns the value of attribute year.



2
3
4
# File 'lib/top_movies/movie.rb', line 2

def year
  @year
end

Class Method Details

.all_timeObject



4
5
6
7
8
# File 'lib/top_movies/movie.rb', line 4

def self.all_time
  #return top movies of this year

  self.scrape_movies
end

.scrape_imdbObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/top_movies/movie.rb', line 18

def self.scrape_imdb
  movie = self.new
  movie.site = "IMDB"
  doc = Nokogiri::HTML(open("http://www.imdb.com/chart/top"))
  movie.name = doc.search("tr td")[1].children.children.first.text
  movie.year = doc.search("tr td")[1].children[3].children.text
  movie.url = doc.search("tr td")[1].children[1].attributes.first.last.value

  movie
end

.scrape_moviesObject



10
11
12
13
14
15
16
# File 'lib/top_movies/movie.rb', line 10

def self.scrape_movies
  deals = []
  deals << self.scrape_imdb
  deals << self.scrape_rotten_tomatoes

  deals
end

.scrape_rotten_tomatoesObject



29
30
31
32
33
34
35
36
37
# File 'lib/top_movies/movie.rb', line 29

def self.scrape_rotten_tomatoes
  movie = self.new
  movie.site = "Rotten Tomatoes"
  doc = Nokogiri::HTML(open("https://www.rottentomatoes.com/top/bestofrt/"))
  movie.name, movie.year = doc.search("tr td")[28].children.children.text.split("\n            ")[1]
  movie.url = "www.rottentomatoes.com"+doc.search("tr td")[28].children[1].attributes.first.last.value

  movie
end