Class: TmdbProfile
Overview
This is the model for the themovieDb profile which is used to find TmdbMovie meta data from either online or from a cached file.
Usage:
profile = TmdbProfile.first(:imdb_id => ‘tt0123456’)
puts profile.movie.first puts profile.to_xml puts profile.imdb_id
Instance Attribute Summary collapse
-
#imdb_id ⇒ Object
readonly
Returns the value of attribute imdb_id.
-
#movie ⇒ Object
readonly
Returns the value of attribute movie.
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
options: :imdb_id => String (either with or without leading ‘tt’) :api_key => String containing themovieDb.com’s API key (required) :filespec => nil or a valid pathspec :logger => nil or a logger instance.
-
.first(options = {}) ⇒ Object
see TmdbProfile.all for description of options.
Instance Method Summary collapse
-
#image ⇒ Object
return the TmdbImage for this profile.
-
#to_xml ⇒ Object
convert to xml returns String (either empty or containing the xml).
Instance Attribute Details
#imdb_id ⇒ Object (readonly)
Returns the value of attribute imdb_id.
50 51 52 |
# File 'lib/tmdb/tmdb_profile.rb', line 50 def imdb_id @imdb_id end |
#movie ⇒ Object (readonly)
Returns the value of attribute movie.
50 51 52 |
# File 'lib/tmdb/tmdb_profile.rb', line 50 def movie @movie end |
Class Method Details
.all(options = {}) ⇒ Object
options:
:imdb_id => String (either with or without leading 'tt')
:api_key => String containing themovieDb.com's API key (required)
:filespec => nil or a valid pathspec
:logger => nil or a logger instance
20 21 22 23 24 25 26 |
# File 'lib/tmdb/tmdb_profile.rb', line 20 def self.all(={}) result = [] if has_option?(, :imdb_id) || (has_option?(, :filespec) && File.exist?([:filespec])) result << TmdbProfile.new([:imdb_id], [:api_key], [:filespec], [:logger]) end result end |
.first(options = {}) ⇒ Object
see TmdbProfile.all for description of options
29 30 31 |
# File 'lib/tmdb/tmdb_profile.rb', line 29 def self.first(={}) self.all().first end |
Instance Method Details
#image ⇒ Object
return the TmdbImage for this profile
64 65 66 |
# File 'lib/tmdb/tmdb_profile.rb', line 64 def image TmdbImage.new(@imdb_id.gsub(/^tt/, ''), @api_key, @logger, @filespec) rescue nil end |
#to_xml ⇒ Object
convert to xml returns String (either empty or containing the xml)
54 55 56 57 58 59 60 61 |
# File 'lib/tmdb/tmdb_profile.rb', line 54 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 |