Method: TVMaze::Show#initialize

Defined in:
lib/tvmaze/show.rb

#initialize(json = {}) ⇒ Show

Returns a new instance of Show.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tvmaze/show.rb', line 17

def initialize(json = {})
  @seasons = []
  @episodes = []

  return if json.nil?
  SHOW_MAPPING.each do |source, destination|
    send("#{destination}=", json[source.to_s] || json[source.to_sym])
  end

  unless json['image'].nil?
    @image_original = json['image']['original']
    @image_medium   = json['image']['medium']
  end

  unless json['_embedded'].nil?
    embedded_json = json['_embedded']
    @next_episode = TVMaze::Episode.new(embedded_json['nextepisode'])
    @episodes = parse_episodes(embedded_json['episodes'])
    @seasons = parse_seasons(@episodes)
  end
end