Class: ImdbMovie
- Inherits:
-
Object
- Object
- ImdbMovie
- Defined in:
- lib/imdb/imdb_movie.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #aspect_ratio ⇒ Object
- #cast_members ⇒ Object
- #color ⇒ Object
- #company ⇒ Object
- #countries ⇒ Object
- #directors ⇒ Object
- #genres ⇒ Object
- #get_data ⇒ Object
-
#initialize(id) ⇒ ImdbMovie
constructor
A new instance of ImdbMovie.
- #languages ⇒ Object
- #length ⇒ Object
- #photos ⇒ Object
- #plot ⇒ Object
- #poster ⇒ Object
- #poster_url ⇒ Object
- #release_date ⇒ Object
- #tagline ⇒ Object
- #title2 ⇒ Object
- #writers ⇒ Object
Constructor Details
#initialize(id) ⇒ ImdbMovie
Returns a new instance of ImdbMovie.
5 6 7 8 |
# File 'lib/imdb/imdb_movie.rb', line 5 def initialize(id) @id = id @url = "http://www.imdb.com/title/tt#{self.id}/" end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/imdb/imdb_movie.rb', line 3 def id @id end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/imdb/imdb_movie.rb', line 3 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/imdb/imdb_movie.rb', line 3 def url @url end |
Instance Method Details
#aspect_ratio ⇒ Object
63 64 65 |
# File 'lib/imdb/imdb_movie.rb', line 63 def aspect_ratio document.search("//h5[text()^='Aspect Ratio']/..").innerHTML.split("\n")[2].gsub(/<.+>.+<\/.+>/, '').strip.unescape_html rescue nil end |
#cast_members ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/imdb/imdb_movie.rb', line 28 def cast_members # document.search("table.cast td.nm a").map { |link| link.innerHTML.strip.unescape_html } rescue [] document.search("table.cast tr").inject([]) do |result, row| a = row.search("td.nm a").innerHTML.strip.unescape_html c = row.search("td.char a").innerHTML.strip.unescape_html if c.empty? c = row.search("td.char").innerHTML.strip.unescape_html end result << [a,c] end end |
#color ⇒ Object
79 80 81 |
# File 'lib/imdb/imdb_movie.rb', line 79 def color document.at("h5[text()='Color:'] ~ a[@href*=color-info']").innerHTML.strip.unescape_html rescue nil end |
#company ⇒ Object
83 84 85 |
# File 'lib/imdb/imdb_movie.rb', line 83 def company document.at("h5[text()='Company:'] ~ a[@href*=/company/']").innerHTML.strip.unescape_html rescue nil end |
#countries ⇒ Object
71 72 73 |
# File 'lib/imdb/imdb_movie.rb', line 71 def countries document.search("h5[text()='Country:'] ~ a[@href*=/Sections/Countries/']").map { |link| link.innerHTML.strip.unescape_html } rescue [] end |
#directors ⇒ Object
14 15 16 |
# File 'lib/imdb/imdb_movie.rb', line 14 def directors document.search("h5[text()^='Director'] ~ a").map { |link| link.innerHTML.strip.unescape_html }.reject { |w| w == 'more' }.uniq rescue [] end |
#genres ⇒ Object
51 52 53 |
# File 'lib/imdb/imdb_movie.rb', line 51 def genres document.search("h5[text()='Genre:'] ~ a[@href*=/Sections/Genres/']").map { |link| link.innerHTML.strip.unescape_html } rescue [] end |
#get_data ⇒ Object
91 92 93 |
# File 'lib/imdb/imdb_movie.rb', line 91 def get_data update_title end |
#languages ⇒ Object
75 76 77 |
# File 'lib/imdb/imdb_movie.rb', line 75 def languages document.search("h5[text()='Language:'] ~ a[@href*=/Sections/Languages/']").map { |link| link.innerHTML.strip.unescape_html } rescue [] end |
#length ⇒ Object
67 68 69 |
# File 'lib/imdb/imdb_movie.rb', line 67 def length document.search("//h5[text()^='Runtime']/..").innerHTML[/\d+ min/] rescue nil end |
#photos ⇒ Object
87 88 89 |
# File 'lib/imdb/imdb_movie.rb', line 87 def photos document.search(".media_strip_thumb img").map { |img| img['src'] } rescue [] end |
#plot ⇒ Object
55 56 57 |
# File 'lib/imdb/imdb_movie.rb', line 55 def plot document.search("//h5[text()^='Plot']/..").innerHTML.split("\n")[2].gsub(/<.+>.+<\/.+>/, '').strip.unescape_html rescue nil end |
#poster ⇒ Object
24 25 26 |
# File 'lib/imdb/imdb_movie.rb', line 24 def poster ImdbImage.new(poster_url) rescue nil end |
#poster_url ⇒ Object
18 19 20 21 22 |
# File 'lib/imdb/imdb_movie.rb', line 18 def poster_url # File.join(self.url, document.at("a[@name='poster']")['href']) rescue nil # File.join("http://www.imdb.com", document.at("a[@name='poster']")['href']) rescue nil document.at("a[@name='poster']")['href'] rescue nil end |
#release_date ⇒ Object
44 45 46 47 48 49 |
# File 'lib/imdb/imdb_movie.rb', line 44 def release_date date = document.search("//h5[text()^='Release Date']/..").innerHTML[/^\d{1,2} \w+ \d{4}/] Date.parse(Chronic.parse(date).strftime('%Y/%m/%d')) rescue nil end |
#tagline ⇒ Object
59 60 61 |
# File 'lib/imdb/imdb_movie.rb', line 59 def tagline document.search("//h5[text()^='Tagline']/..").innerHTML.split("\n")[2].gsub(/<.+>.+<\/.+>/, '').strip.unescape_html rescue nil end |
#title2 ⇒ Object
95 96 97 |
# File 'lib/imdb/imdb_movie.rb', line 95 def title2 document.at("div#tn15title h1").innerHTML.split('<span>').first.unescape_html rescue nil end |
#writers ⇒ Object
40 41 42 |
# File 'lib/imdb/imdb_movie.rb', line 40 def writers document.search("h5[text()^='Writer'] ~ a").map { |link| link.innerHTML.strip.unescape_html }.reject { |w| w == 'more' }.uniq rescue [] end |