Class: ImdbProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/imdb/imdb_profile.rb

Overview

This is the model for the IDMB profile which is used to find ImdbMovie meta data from either online or from a cached file.

Usage:

profiles = ImdbProfile.all(:titles => [‘The Alamo’])

profile = ImdbProfile.first(:imdb_id => ‘tt0123456’) or profile = ImdbProfile.first(:titles => [‘movie title 1’, ‘movie title 2’,…]

:media_years => ['2000'],
:production_years => ['1999'],
:released_years => ['2002', '2008']
:filespec => media.path_to(:imdb_xml))

puts profile.movie.first puts profile.to_xml puts profile.imdb_id

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#imdb_idObject (readonly)

returns the IMDB ID String



76
77
78
# File 'lib/imdb/imdb_profile.rb', line 76

def imdb_id
  @imdb_id
end

#movieObject (readonly)

returns a Hash with the movie’s meta data generated from ImdbMovie.to_hash. See ImdbMovie for details.



80
81
82
# File 'lib/imdb/imdb_profile.rb', line 80

def movie
  @movie
end

Class Method Details

.all(options = {}) ⇒ Object

options:

:imdb_id          => String containing the IMDB ID (ex: 'tt0465234')
                     Note, the leading 'tt' is optional.
:titles           => titles,
:media_years      => Array of integer, 4 digit years (ex: [1998]).
                     Should be the year(s) from the media file name.
                     This let's the user say what year when they name
                     the file.
:production_years => Array of integer, 4 digit years (ex: [1997,1998]).
                     Should be the year(s) the movie was made.
                     Note, some databases differ on the production year.
:released_years   => Array of integer, 4 digit years (ex: [1998, 2008])
                     Should be the year(s) the movie was released.
:logger           => Logger instance

returns Array of ImdbProfile instances



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/imdb/imdb_profile.rb', line 38

def self.all(options={})
  @class_logger = OptionalLogger.new(options[:logger])
  @class_logger.debug {"ImdbProfile.all(#{options.inspect})"} unless options[:logger].nil?
  result = []
  if has_option?(options, :imdb_id) || (has_option?(options, :filespec) && File.exist?(options[:filespec]))
    result << ImdbProfile.new(options[:imdb_id], options[:filespec], options[:logger])
  elsif has_option?(options, :titles)
    result += self.lookup(options[:titles],
                          options[:media_years],
                          options[:production_years],
                          options[:released_years]
                        ).collect{|ident| ImdbProfile.new(ident, options[:filespec], options[:logger])}
  end
  result
end

.first(options = {}) ⇒ Object

see ImdbProfile.all for options description



55
56
57
# File 'lib/imdb/imdb_profile.rb', line 55

def self.first(options={})
  self.all(options).first
end

Instance Method Details

#to_xmlObject

return the xml as a String



83
84
85
86
87
88
89
90
# File 'lib/imdb/imdb_profile.rb', line 83

def to_xml
  xml = ''
  unless @movie.blank?
    @movie.delete_if { |key, value| value.nil? }
    xml = XmlSimple.xml_out(@movie, 'NoAttr' => true, 'RootName' => 'movie')
  end
  xml
end