Class: TopBox::Movie
- Inherits:
-
Object
- Object
- TopBox::Movie
- Defined in:
- lib/top_box/movie.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#metascore ⇒ Object
Returns the value of attribute metascore.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#review_url ⇒ Object
Returns the value of attribute review_url.
-
#reviews ⇒ Object
Returns the value of attribute reviews.
-
#runtime ⇒ Object
Returns the value of attribute runtime.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#title ⇒ Object
Returns the value of attribute title.
-
#total_gross ⇒ Object
Returns the value of attribute total_gross.
-
#url ⇒ Object
Returns the value of attribute url.
-
#weeks_in_theater ⇒ Object
Returns the value of attribute weeks_in_theater.
Class Method Summary collapse
Instance Method Summary collapse
- #get_movie_details ⇒ Object
- #get_reviews ⇒ Object
-
#initialize(attribute_hash) ⇒ Movie
constructor
A new instance of Movie.
- #num ⇒ Object
Constructor Details
#initialize(attribute_hash) ⇒ Movie
Returns a new instance of Movie.
5 6 7 8 9 10 11 12 |
# File 'lib/top_box/movie.rb', line 5 def initialize(attribute_hash) @title = attribute_hash[:title] @weeks_in_theater = attribute_hash[:weeks_in_theater] @total_gross = attribute_hash[:total_gross] @url = attribute_hash[:url] @reviews = [] @@all << self end |
Instance Attribute Details
#metascore ⇒ Object
Returns the value of attribute metascore.
2 3 4 |
# File 'lib/top_box/movie.rb', line 2 def @metascore end |
#rating ⇒ Object
Returns the value of attribute rating.
2 3 4 |
# File 'lib/top_box/movie.rb', line 2 def @rating end |
#review_url ⇒ Object
Returns the value of attribute review_url.
2 3 4 |
# File 'lib/top_box/movie.rb', line 2 def review_url @review_url end |
#reviews ⇒ Object
Returns the value of attribute reviews.
2 3 4 |
# File 'lib/top_box/movie.rb', line 2 def reviews @reviews end |
#runtime ⇒ Object
Returns the value of attribute runtime.
2 3 4 |
# File 'lib/top_box/movie.rb', line 2 def runtime @runtime end |
#summary ⇒ Object
Returns the value of attribute summary.
2 3 4 |
# File 'lib/top_box/movie.rb', line 2 def summary @summary end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/top_box/movie.rb', line 2 def title @title end |
#total_gross ⇒ Object
Returns the value of attribute total_gross.
2 3 4 |
# File 'lib/top_box/movie.rb', line 2 def total_gross @total_gross end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/top_box/movie.rb', line 2 def url @url end |
#weeks_in_theater ⇒ Object
Returns the value of attribute weeks_in_theater.
2 3 4 |
# File 'lib/top_box/movie.rb', line 2 def weeks_in_theater @weeks_in_theater end |
Class Method Details
.all ⇒ Object
14 15 16 |
# File 'lib/top_box/movie.rb', line 14 def self.all @@all end |
Instance Method Details
#get_movie_details ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/top_box/movie.rb', line 26 def get_movie_details movie_page = Scraper.scrape_movie_page(@url) #'/title/tt3104988' @summary = movie_page.css('.inline.canwrap span')[0].text.strip @metascore = movie_page.css('.metacriticScore').text.strip @rating = movie_page.css('.txt-block span')[0].text.capitalize @runtime = movie_page.css('.txt-block time').text @review_url = movie_page.css('.titleReviewBarSubItem a').attribute('href').value end |
#get_reviews ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/top_box/movie.rb', line 36 def get_reviews if @reviews == [] reviews_array = Scraper.scrape_review_page("#{@url}/#{@review_url}") reviews_array.each do |x| a = TopBox::Review.new(x) @reviews << a end end end |
#num ⇒ Object
18 19 20 |
# File 'lib/top_box/movie.rb', line 18 def num @@all.index(self)+1 end |