Class: TopBox::Movie

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#metascoreObject

Returns the value of attribute metascore.


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

def metascore
  @metascore
end

#ratingObject

Returns the value of attribute rating.


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

def rating
  @rating
end

#review_urlObject

Returns the value of attribute review_url.


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

def review_url
  @review_url
end

#reviewsObject

Returns the value of attribute reviews.


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

def reviews
  @reviews
end

#runtimeObject

Returns the value of attribute runtime.


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

def runtime
  @runtime
end

#summaryObject

Returns the value of attribute summary.


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

def summary
  @summary
end

#titleObject

Returns the value of attribute title.


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

def title
  @title
end

#total_grossObject

Returns the value of attribute total_gross.


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

def total_gross
  @total_gross
end

#urlObject

Returns the value of attribute url.


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

def url
  @url
end

#weeks_in_theaterObject

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

.allObject


14
15
16
# File 'lib/top_box/movie.rb', line 14

def self.all
  @@all
end

.new_from_collection(movies_attributes_array) ⇒ Object


22
23
24
# File 'lib/top_box/movie.rb', line 22

def self.new_from_collection(movies_attributes_array)
  movies_attributes_array.each{ |x| TopBox::Movie.new(x) }
end

Instance Method Details

#get_movie_detailsObject


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_reviewsObject


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

#numObject


18
19
20
# File 'lib/top_box/movie.rb', line 18

def num
  @@all.index(self)+1
end