Class: IMDb::Title

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

Overview

pass any Movie, TV-show, Episode or Game url from imdb.com

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Title

Returns a new instance of Title.

Raises:



21
22
23
24
25
26
27
28
29
30
# File 'lib/imdb_title.rb', line 21

def initialize(url)
  raise InvalidURL, "Please input a valid IMDb URL" unless valid?(url)

  case media_type
  when "video.movie" then extend Movie
  when "video.tv_show" then extend TvShow
  when "video.episode" then extend Episode
  when "video.other" then extend VideoGame
  end
end

Instance Method Details

#castsObject

lists all top cast (Array)



33
34
35
36
37
38
# File 'lib/imdb_title.rb', line 33

def casts
  html = document.css("a[data-testid=title-cast-item__actor]")
  return if html.empty?

  html.map(&:text)
end

#directorsObject

list of directors (Array)



41
42
43
44
45
46
# File 'lib/imdb_title.rb', line 41

def directors
  html = document.css("li[data-testid=title-pc-principal-credit]").first
  return unless html.text.match?(/Director|Creator/)

  html.css("div li").map(&:text)
end

#genresObject

list of genres (Array)



49
50
51
# File 'lib/imdb_title.rb', line 49

def genres
  document.css("div[data-testid=genres] div a").map(&:text)
end

#imdb_idObject

ID that differentiates each media type on imdb.com (String)



54
55
56
# File 'lib/imdb_title.rb', line 54

def imdb_id
  document.css("meta[property*=pageConst]").attribute("content").value
end

#popularityObject

number of users rated (String)



59
60
61
# File 'lib/imdb_title.rb', line 59

def popularity
  document.css("div[data-testid=hero-rating-bar__aggregate-rating] span div").last&.text
end

#production_companiesObject

list of production companies (Array)



64
65
66
# File 'lib/imdb_title.rb', line 64

def production_companies
  document.css("li[data-testid=title-details-companies] li").map(&:text)
end

#ratingsObject

average ratings (String)



69
70
71
# File 'lib/imdb_title.rb', line 69

def ratings
  document.css("div[data-testid=hero-rating-bar__aggregate-rating__score] span").first&.text
end

#release_dateObject

the date it was release on (String)



74
75
76
# File 'lib/imdb_title.rb', line 74

def release_date
  document.css("li[data-testid=title-details-releasedate] div").first&.text
end

#taglineObject

short introduction



79
80
81
# File 'lib/imdb_title.rb', line 79

def tagline
  document.css("span[data-testid=plot-xl]").first&.text
end

#titleObject

name or title



84
85
86
# File 'lib/imdb_title.rb', line 84

def title
  document.css("h1").text
end

#urlObject

full url



89
90
91
# File 'lib/imdb_title.rb', line 89

def url
  document.css("meta[property*=url]").attribute("content").value
end