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 |
# File 'lib/imdb_title.rb', line 33 def casts document.css("a[data-testid=title-cast-item__actor]").map(&:text) || [] end |
#directors ⇒ Object
list of directors (Array)
38 39 40 41 |
# File 'lib/imdb_title.rb', line 38 def directors element = document.css("li[data-testid=title-pc-principal-credit]").first element&.text&.match?(/Director|Creator/) ? element.css("div li").map(&:text) : [] end |
#genres ⇒ Object
list of genres (Array)
44 45 46 |
# File 'lib/imdb_title.rb', line 44 def genres document.css("div[data-testid=interests] div a").map(&:text) || [] end |
#imdb_id ⇒ Object
ID that differentiates each media type on imdb.com (String)
49 50 51 |
# File 'lib/imdb_title.rb', line 49 def imdb_id document.css("meta[property*=pageConst]").attribute("content").value end |
#popularity ⇒ Object
number of users rated (String)
54 55 56 |
# File 'lib/imdb_title.rb', line 54 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)
59 60 61 |
# File 'lib/imdb_title.rb', line 59 def production_companies document.css("li[data-testid=title-details-companies] li").map(&:text) || [] end |
#ratings ⇒ Object
average ratings (String)
64 65 66 |
# File 'lib/imdb_title.rb', line 64 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)
69 70 71 |
# File 'lib/imdb_title.rb', line 69 def release_date document.css("li[data-testid=title-details-releasedate] div").first&.text end |
#tagline ⇒ Object
short introduction
74 75 76 |
# File 'lib/imdb_title.rb', line 74 def tagline document.css("span[data-testid=plot-xl]").first&.text end |
#title ⇒ Object
name or title
79 80 81 |
# File 'lib/imdb_title.rb', line 79 def title document.css("h1").text end |
#url ⇒ Object
full url
84 85 86 |
# File 'lib/imdb_title.rb', line 84 def url document.css("meta[property*=url]").attribute("content").value end |