class TTVDB::Series
Attributes
actors[R]
added[R]
added_by[R]
airs_dayofweek[R]
airs_time[R]
client[RW]
content_rating[R]
fanart[R]
first_aired[R]
genre[R]
id[R]
imdb_id[R]
language[R]
last_updated[R]
name[R]
network[R]
network_id[R]
overview[R]
poster[R]
rating[R]
rating_count[R]
runtime[R]
seasons[R]
series_id[R]
series_name[R]
status[R]
zap2it_id[R]
Public Class Methods
new(data)
click to toggle source
# File lib/ttvdb/series.rb, line 14 def initialize(data) @data = Hash[data.map { |k, v| [k.downcase, v] }] parse @seasons = {} end
Public Instance Methods
episodes()
click to toggle source
# File lib/ttvdb/series.rb, line 20 def episodes @episodes ||= fetch_episodes end
Private Instance Methods
fetch_episodes()
click to toggle source
# File lib/ttvdb/series.rb, line 25 def fetch_episodes raise Exception, "client not configured" unless @client @episodes = @client.get_episodes_by_series_id @id return unless @episodes @episodes.each do |episode| unless @seasons[episode.season_number] @seasons[episode.season_number] = {} end @seasons[episode.season_number][episode.number] = episode end @seasons = Hash[@seasons.sort_by {|k,v| k.to_i }] sort_episodes! end
sort_episodes!()
click to toggle source
# File lib/ttvdb/series.rb, line 39 def sort_episodes! special = [] sorted = {} @seasons.each do |season, data| data.each do |n, e| if season == 0 special << e else sorted[season] ||= [] sorted[season] << e end end end sorted = Hash[sorted.sort_by {|k,v| k.to_i }] new_episodes = [] sorted.each do |season, episodes| new_episodes << episodes end new_episodes << special # specials at the end @episodes = new_episodes.flatten.compact end