Class: IMDB::Movie
Overview
Get movie information with IMDB movie id.
Instance Attribute Summary collapse
-
#imdb_id ⇒ Object
Returns the value of attribute imdb_id.
-
#link ⇒ Object
Returns the value of attribute link.
Attributes inherited from Skeleton
Instance Method Summary collapse
-
#cast ⇒ Array
Get movie cast listing.
-
#director ⇒ String
Get Director.
-
#genres ⇒ Array
Genre List.
-
#initialize(id_of) ⇒ Movie
constructor
A new instance of Movie.
-
#photos ⇒ Array
Get movie photos.
-
#poster ⇒ String
Get movie poster address.
-
#release_date ⇒ String
Get release date.
-
#title ⇒ String
Get movie title.
-
#writers ⇒ Array
Writer List.
Methods inherited from Skeleton
json_create, #to_hash, #to_json
Constructor Details
#initialize(id_of) ⇒ Movie
Returns a new instance of Movie.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/imdb/movie.rb', line 10 def initialize(id_of) # !!!DON'T FORGET DEFINE NEW METHODS IN SUPER!!! super("Movie", {:imdb_id => String, :poster => String, :title => String, :release_date => String, :cast => Array, :photos => Array, :director => String, :genres => Array, :writers => Array}, [:imdb_id]) @imdb_id = id_of @link = "http://www.imdb.com/title/tt#{@imdb_id}" end |
Instance Attribute Details
#imdb_id ⇒ Object
Returns the value of attribute imdb_id.
7 8 9 |
# File 'lib/imdb/movie.rb', line 7 def imdb_id @imdb_id end |
#link ⇒ Object
Returns the value of attribute link.
7 8 9 |
# File 'lib/imdb/movie.rb', line 7 def link @link end |
Instance Method Details
#cast ⇒ Array
Get movie cast listing
41 42 43 44 45 46 47 48 49 |
# File 'lib/imdb/movie.rb', line 41 def cast doc.search("table.cast tr").map do |link| picture = link.children[0].search("img")[0]["src"] rescue nil name = link.children[1].content.strip rescue nil profile_id = link.children[1].search('a[@href^="/name/nm"]').first["href"] rescue nil char = link.children[3].content.strip rescue nil IMDB::Person.new(@imdb_id, name, char, profile_id, picture) unless name.nil? and char.nil? and picture.nil? and profile_id.nil? end end |
#director ⇒ String
Get Director
73 74 75 |
# File 'lib/imdb/movie.rb', line 73 def director doc.xpath("//h5[contains(., 'Director')]/..").at("a").content rescue nil end |
#genres ⇒ Array
Genre List
79 80 81 82 83 84 85 |
# File 'lib/imdb/movie.rb', line 79 def genres doc.xpath("//h5[contains(., 'Genre')]/..").search("a").map { |g| g.content unless g.content =~ /See more/ }.compact rescue nil end |
#photos ⇒ Array
Get movie photos
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/imdb/movie.rb', line 53 def photos begin doc.search("img").map { |img| unless img["src"][/_CR/].nil? img["src"] end } rescue nil end end |
#poster ⇒ String
Get movie poster address
29 30 31 |
# File 'lib/imdb/movie.rb', line 29 def poster doc.at("a[@name='poster'] img")['src'][/http:.+/] + '.jpg' rescue nil end |
#release_date ⇒ String
Get release date
67 68 69 |
# File 'lib/imdb/movie.rb', line 67 def release_date Date.parse(Chronic.parse(doc.xpath("//h5[contains(., 'Release Date')]/..").first.content[/^\d{1,2} \w+ \d{4}/]).strftime('%Y/%m/%d')).to_s rescue nil end |
#title ⇒ String
Get movie title
35 36 37 |
# File 'lib/imdb/movie.rb', line 35 def title doc.at("//head/meta[@name='title']")["content"].split(/\(\d+\)/)[0].strip! end |