Class: Tmdb::Credit

Inherits:
Struct show all
Defined in:
lib/tmdb/credit.rb

Class Method Summary collapse

Methods inherited from Struct

#analyze_value, #initialize

Constructor Details

This class inherits a constructor from Tmdb::Struct

Class Method Details

.detail(id, filters = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tmdb/credit.rb', line 4

def self.detail(id, filters={})
  result = Resource.new("/credit/#{id}", filters).get

  media = result['media']

  credit = self.new(result.except('media', 'person'))
  credit.media = Media.new(media.except('episodes', 'seasons'))

  if media['episodes'].present?
    credit.media.episodes = media['episodes'].map do |episode|
      Tv::Episode.new(episode)
    end
  end

  if media['seasons'].present?
    credit.media.seasons = media['seasons'].map do |season|
      Tv::Season.new(season)
    end
  end

  credit.person = Person.new(result['person'])

  credit
end