Class: ImdbInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/dvdprofiler2xbmc/models/imdb_info.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(options) ⇒ Object

Synopsis

See ImdbProfile.all for options



12
13
14
15
16
17
18
19
# File 'lib/dvdprofiler2xbmc/models/imdb_info.rb', line 12

def self.find(options)
  imdb_info = nil
  profile = ImdbProfile.first(options)
  unless profile.nil?
    imdb_info = ImdbInfo.new(profile)
  end
  imdb_info
end

Instance Method Details

#imdb_idObject



73
74
75
# File 'lib/dvdprofiler2xbmc/models/imdb_info.rb', line 73

def imdb_id
  @profile.imdb_id rescue nil
end

#to_xbmc_infoObject

Synopsis

maps the imdb.movie hash to the info hash



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dvdprofiler2xbmc/models/imdb_info.rb', line 44

def to_xbmc_info
  info = Hash.new
  unless @profile.movie.blank?
    IMDB_HASH_TO_INFO_MAP.each do |key, value|
      info[value] = @profile.movie[key] unless @profile.movie[key].blank?
    end
    info['id'] = self.imdb_id if info['id'].blank?
    # special cases:
    if info['mpaa'].blank? && !@profile.movie['certifications'].blank?
      @profile.movie['certifications'].each do |certs|
        if certs['country'] == 'USA'
          AppConfig[:logger].info { "Using alternative USA certification instead of mpaa rating" }
          info['mpaa'] = certs['rating'] unless certs['rating'].blank?
          break
        end
      end
    end
    unless @profile.movie['cast_members'].blank?
      @profile.movie['cast_members'].each do |anon|
        # anon[2] => {name,role}
        info['actor'] ||= []
        info['actor'] << {'name' => anon[0], 'role' => anon[1]}
      end
    end
    info['year'] ||= @profile.movie['release_year']
  end
  info
end