Class: ImdbProfile
- Inherits:
-
Object
- Object
- ImdbProfile
- 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
-
#imdb_id ⇒ Object
readonly
returns the IMDB ID String.
-
#movie ⇒ Object
readonly
returns a Hash with the movie’s meta data generated from ImdbMovie.to_hash.
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
options: :imdb_id => String containing the IMDB ID (ex: ‘tt0465234’) Note, the leading ‘tt’ is optional.
-
.first(options = {}) ⇒ Object
see ImdbProfile.all for options description.
Instance Method Summary collapse
-
#to_xml ⇒ Object
return the xml as a String.
Instance Attribute Details
#imdb_id ⇒ Object (readonly)
returns the IMDB ID String
76 77 78 |
# File 'lib/imdb/imdb_profile.rb', line 76 def imdb_id @imdb_id end |
#movie ⇒ Object (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(={}) @class_logger = OptionalLogger.new([:logger]) @class_logger.debug {"ImdbProfile.all(#{.inspect})"} unless [:logger].nil? result = [] if has_option?(, :imdb_id) || (has_option?(, :filespec) && File.exist?([:filespec])) result << ImdbProfile.new([:imdb_id], [:filespec], [:logger]) elsif has_option?(, :titles) result += self.lookup([:titles], [:media_years], [:production_years], [:released_years] ).collect{|ident| ImdbProfile.new(ident, [:filespec], [: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(={}) self.all().first end |
Instance Method Details
#to_xml ⇒ Object
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 |