Class: IMDb::Title
- Inherits:
-
Object
- Object
- IMDb::Title
- Defined in:
- lib/imdb_title.rb
Overview
pass any Movie, TV-show, Episode or Game url from imdb.com
Instance Method Summary collapse
-
#casts ⇒ Object
lists all top cast (Array).
-
#directors ⇒ Object
list of directors (Array).
-
#genres ⇒ Object
list of genres (Array).
-
#imdb_id ⇒ Object
ID that differentiates each media type on imdb.com (String).
-
#initialize(url) ⇒ Title
constructor
A new instance of Title.
-
#popularity ⇒ Object
number of users rated (String).
-
#production_companies ⇒ Object
list of production companies (Array).
-
#ratings ⇒ Object
average ratings (String).
-
#release_date ⇒ Object
the date it was release on (String).
-
#tagline ⇒ Object
short introduction.
-
#title ⇒ Object
name or title.
-
#url ⇒ Object
full url.
Constructor Details
#initialize(url) ⇒ Title
Returns a new instance of Title.
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
#casts ⇒ Object
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 |
#directors ⇒ Object
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 |
#genres ⇒ Object
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_id ⇒ Object
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 |
#popularity ⇒ Object
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_companies ⇒ Object
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 |
#ratings ⇒ Object
average ratings (String)
69 70 71 |
# File 'lib/imdb_title.rb', line 69 def document.css("div[data-testid=hero-rating-bar__aggregate-rating__score] span").first&.text end |
#release_date ⇒ Object
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 |
#tagline ⇒ Object
short introduction
79 80 81 |
# File 'lib/imdb_title.rb', line 79 def tagline document.css("span[data-testid=plot-xl]").first&.text end |
#title ⇒ Object
name or title
84 85 86 |
# File 'lib/imdb_title.rb', line 84 def title document.css("h1").text end |
#url ⇒ Object
full url
89 90 91 |
# File 'lib/imdb_title.rb', line 89 def url document.css("meta[property*=url]").attribute("content").value end |