Class: BoxOffice::Movies

Inherits:
Object
  • Object
show all
Defined in:
lib/boxoffice/movies.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#a_scoreObject

Returns the value of attribute a_score.



2
3
4
# File 'lib/boxoffice/movies.rb', line 2

def a_score
  @a_score
end

#ccObject

Returns the value of attribute cc.



2
3
4
# File 'lib/boxoffice/movies.rb', line 2

def cc
  @cc
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/boxoffice/movies.rb', line 2

def name
  @name
end

#rt_scoreObject

Returns the value of attribute rt_score.



2
3
4
# File 'lib/boxoffice/movies.rb', line 2

def rt_score
  @rt_score
end

#top_threeObject

Returns the value of attribute top_three.



2
3
4
# File 'lib/boxoffice/movies.rb', line 2

def top_three
  @top_three
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/boxoffice/movies.rb', line 2

def url
  @url
end

Class Method Details

.more_infoObject



33
34
35
36
37
38
39
40
# File 'lib/boxoffice/movies.rb', line 33

def self.more_info
  top_three = self.mov_info
   top_three.each.with_index do |movie, i|
     doc2 = Nokogiri::HTML(open("https://www.rottentomatoes.com#{top_three[i.to_i].url}"))
     top_three[i.to_i].cc = doc2.css("#scorePanel .col-full-xs").text.strip
     top_three[i.to_i].a_score = doc2.css("#scorePanel .audience-score .media-body .meter-value").text.strip
   end
end

.mov_infoObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/boxoffice/movies.rb', line 11

def self.mov_info
  doc1 = Nokogiri::HTML(open("https://www.rottentomatoes.com/"))

    movie_1 = self.new
    movie_1.name = doc1.css("#homepage-top-box-office .movie_list .middle_col")[0].text.strip
    movie_1.rt_score = doc1.css("#homepage-top-box-office .movie_list .left_col")[0].text.strip
    movie_1.url = doc1.css("#homepage-top-box-office .movie_list .middle_col a")[0].attr("href")

    movie_2 = self.new
    movie_2.name = doc1.css("#homepage-top-box-office .movie_list .middle_col")[1].text.strip
    movie_2.rt_score = doc1.css("#homepage-top-box-office .movie_list .left_col")[1].text.strip
    movie_2.url = doc1.css("#homepage-top-box-office .movie_list .middle_col a")[1].attr("href")

    movie_3 = self.new
    movie_3.name = doc1.css("#homepage-top-box-office .movie_list .middle_col")[2].text.strip
    movie_3.rt_score = doc1.css("#homepage-top-box-office .movie_list .left_col")[2].text.strip
    movie_3.url = doc1.css("#homepage-top-box-office .movie_list .middle_col a")[2].attr("href")

    [movie_1, movie_2, movie_3]
end

.todayObject



5
6
7
8
# File 'lib/boxoffice/movies.rb', line 5

def self.today
  self.mov_info
  self.more_info
end