Class: Ofdb::Movie

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

Overview

Wraps a Ofdb-Movie-Page to Ruby. This Class is Lazy-Load, means that the Pages are only loaded when needed. Also the data mining is only done when needed

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ofdb_link) ⇒ Movie

Take a link to a Ofdb-page of a Movie and builds the Ofdb::Movie The full link isn’t require, e.g. for www.ofdb.de/film/1050,Pulp-Fiction only “1050,Pulp-Fiction” is required.



24
25
26
27
28
29
30
31
32
33
# File 'lib/ofdb/movie.rb', line 24

def initialize(ofdb_link)
  if ofdb_link =~ /http:\/\/www.ofdb.de\/film/
    @name = ofdb_link.gsub("http:\/\/www.ofdb.de\/film")
    @url = ofdb_link
  else
    @name = ofdb_link
    @url = "http://www.ofdb.de/film/#{@name}"
  end
  @title = /\d,/.match(name).post_match.gsub("---","§§§").gsub("-", " ").gsub("§§§", " - ")
end

Instance Attribute Details

#nameObject (readonly)

holds the “ofdb-id”



9
10
11
# File 'lib/ofdb/movie.rb', line 9

def name
  @name
end

#posterObject

Returns a URL to the Poster



11
12
13
# File 'lib/ofdb/movie.rb', line 11

def poster
  @poster
end

#titleObject (readonly)

holds the title of this movie



7
8
9
# File 'lib/ofdb/movie.rb', line 7

def title
  @title
end

Class Method Details

.build_from_imdb(id) ⇒ Object

Takes a IMDB-ID and call a serch with Ofdb::Search If the serch returns exactly 1 Movie then this Movie is return, else nil



15
16
17
18
19
# File 'lib/ofdb/movie.rb', line 15

def Movie.build_from_imdb(id)
  search = Ofdb::Search.new(id, true)
  return search.movies.first if search.movies.size == 1
  nil
end

Instance Method Details

#countriesObject

Returns an Array conating the Countries this film was filmed in



72
73
74
# File 'lib/ofdb/movie.rb', line 72

def countries
  get_viewphp("Kat=Land").map {|x|  x.innerHTML }
end

#genreObject

Returns a Array containg the Genres



67
68
69
# File 'lib/ofdb/movie.rb', line 67

def genre
  get_viewphp("page=genre&Genre=").map {|x|  x.innerHTML }
end

#imdbObject

Returns a IMDB-ID



36
37
38
39
40
# File 'lib/ofdb/movie.rb', line 36

def imdb
  document.search('a[@href^="http://www.imdb.com/"]').each do |x|
    return x.get_attribute("href").to_s.gsub("http://www.imdb.com/Title?", "")
  end
end

#plotObject

Returns s String containing the Plot



43
44
45
46
47
48
49
50
51
52
# File 'lib/ofdb/movie.rb', line 43

def plot
  document.search('a[@href^="plot/"]').each do |x|
    @plot_doc ||= Hpricot(open("http://www.ofdb.de/"+x.get_attribute("href")))
    @plot_doc.search('//font[@class=Blocksatz]/').each do |y|
      #next unless y.search('a[@href="usercenter/"')
      next if y.to_s =~ /<b>/ || y.to_s =~ /<\/b>/ || y.to_s =~ /<br \/>/
      return y.to_s.strip
    end
  end
end

#yearObject

Returns the year this movie was Filmed in



77
78
79
# File 'lib/ofdb/movie.rb', line 77

def year
  get_viewphp("Kat=Jahr").each {|x|  return x.innerHTML }
end