Class: TmdbProfile

Inherits:
Object show all
Defined in:
lib/tmdb/tmdb_profile.rb

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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#imdb_idObject (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

#movieObject (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(options={})
  result = []
  if has_option?(options, :imdb_id) || (has_option?(options, :filespec) && File.exist?(options[:filespec]))
    result << TmdbProfile.new(options[:imdb_id], options[:api_key], options[:filespec], options[: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(options={})
  self.all(options).first
end

Instance Method Details

#imageObject

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_xmlObject

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