Class: TheTvdb::Show

Inherits:
Object
  • Object
show all
Defined in:
lib/the_tvdb/show.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info, partial = false) ⇒ Show

Returns a new instance of Show.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/the_tvdb/show.rb', line 26

def initialize(info, partial=false)
  @remote_id = info['id'].to_i
  @name = info['SeriesName']
  @banner = "#{TheTvdb.gateway.mirror}/banners/#{info['banner']}" unless info['banner'].nil?
  @description = info['Overview']
  @imdb_id = info['IMDB_ID']
  @zap2it_id = info['zap2it_id']
  @first_aired = info['FirstAired']
  @language = info['language']

  unless partial
    @episodes = []
    @actors = info['Actors'].try(:to_tvdb_array)
    @airs_day_of_week = info['Airs_DayOfWeek']
    @airs_time = info['Airs_Time']
    @content_rating =  info['ContentRating']
    @genre = info['Genre'].try(:to_tvdb_array)
    @network = info['Network']
    @runtime = info['Runtime'].try(:to_i)
    @fanart = "#{TheTvdb.gateway.mirror}/banners/#{info['fanart']}" unless info['fanart'].nil?
    @rating = info['Rating'].try(:to_f)
    @rating_count = info['RatingCount'].try(:to_i)
    @status = info['Status']
    @added_at = info['added']
    @last_updated = info['lastupdated']
    @poster = "#{TheTvdb.gateway.mirror}/banners/#{info['poster']}" unless info['poster'].nil?
  end

end

Instance Attribute Details

#actorsObject

Returns the value of attribute actors.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def actors
  @actors
end

#added_atObject

Returns the value of attribute added_at.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def added_at
  @added_at
end

#airs_day_of_weekObject

Returns the value of attribute airs_day_of_week.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def airs_day_of_week
  @airs_day_of_week
end

#airs_timeObject

Returns the value of attribute airs_time.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def airs_time
  @airs_time
end

Returns the value of attribute banner.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def banner
  @banner
end

#content_ratingObject

Returns the value of attribute content_rating.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def content_rating
  @content_rating
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def description
  @description
end

#episodesObject

Returns the value of attribute episodes.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def episodes
  @episodes
end

#fanartObject

Returns the value of attribute fanart.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def fanart
  @fanart
end

#first_airedObject

Returns the value of attribute first_aired.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def first_aired
  @first_aired
end

#genreObject

Returns the value of attribute genre.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def genre
  @genre
end

#imdb_idObject

Returns the value of attribute imdb_id.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def imdb_id
  @imdb_id
end

#languageObject

Returns the value of attribute language.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def language
  @language
end

#last_updatedObject

Returns the value of attribute last_updated.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def last_updated
  @last_updated
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def name
  @name
end

#networkObject

Returns the value of attribute network.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def network
  @network
end

#posterObject

Returns the value of attribute poster.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def poster
  @poster
end

#ratingObject

Returns the value of attribute rating.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def rating
  @rating
end

#rating_countObject

Returns the value of attribute rating_count.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def rating_count
  @rating_count
end

#remote_idObject

Returns the value of attribute remote_id.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def remote_id
  @remote_id
end

#runtimeObject

Returns the value of attribute runtime.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def runtime
  @runtime
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def status
  @status
end

#zap2it_idObject

Returns the value of attribute zap2it_id.



4
5
6
# File 'lib/the_tvdb/show.rb', line 4

def zap2it_id
  @zap2it_id
end

Class Method Details

.find(remote_id) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/the_tvdb/show.rb', line 14

def self.find(remote_id)
  begin
    info = TheTvdb.gateway.get_series_package(remote_id)
    show = self.new(info['Series'])
    show.episodes = info['Episode'].blank? ? [] : [ info['Episode'] ].flatten.map {|e| TheTvdb::Episode.new(e) }
    show
  rescue
    puts 'There was an issue with the series you tried to fetch'
    nil
  end
end

.search(name) ⇒ Object



9
10
11
12
# File 'lib/the_tvdb/show.rb', line 9

def self.search(name)
  shows = TheTvdb.gateway.get_series(name)
  shows.map {|s| self.new(s, true) }
end

Instance Method Details

#to_hashObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/the_tvdb/show.rb', line 56

def to_hash
  { 
    remote_id: @remote_id,
    name: @name,
    banner: @banner,
    description: @description,
    first_aired: @first_aired,
    imdb_id: @imdb_id,
    zap2it_id: @zap2it_id,
    language: @language,
    actors: @actors,
    airs_day_of_week: @airs_day_of_week,
    airs_time: @airs_time,
    content_rating: @content_rating,
    genre: @genre,
    network: @network,
    runtime: @runtime,
    fanart: @fanart,
    rating: @rating,
    rating_count: @rating_count,
    status: @status,
    added_at: @added_at,
    last_updated: @last_updated,
    poster: @poster
  }
end