Class: Tvdb2::Series
- Inherits:
-
Object
- Object
- Tvdb2::Series
- Defined in:
- lib/tvdb2/series.rb
Overview
This class rappresent a series retrieved from TVDB api.
Constant Summary
- INDEX_FIELDS =
Fields returned from api endpoint
GET /search/series
(search) [ :aliases, :banner, :firstAired, :id, :network, :overview, :seriesName, :status ]
- SHOW_FIELDS =
Other fields with INDEX_FIELDS returned from api endpoint
GET /series/{id}
[ :added, :airsDayOfWeek, :airsTime, :genre, :imdbId, :lastUpdated, :networkId, :rating, :runtime, :seriesId, :siteRating, :siteRatingCount, :zap2itId ]
- FIELDS =
All possible data fields returned from api for a series.
INDEX_FIELDS + SHOW_FIELDS
Instance Attribute Summary collapse
-
#added ⇒ Object
readonly
Returns the value of attribute added.
-
#airsDayOfWeek ⇒ Object
readonly
Returns the value of attribute airsDayOfWeek.
-
#airsTime ⇒ Object
readonly
Returns the value of attribute airsTime.
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#banner ⇒ Object
readonly
Returns the value of attribute banner.
-
#firstAired ⇒ Object
readonly
Returns the value of attribute firstAired.
-
#genre ⇒ Object
readonly
Returns the value of attribute genre.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#imdbId ⇒ Object
readonly
Returns the value of attribute imdbId.
-
#lastUpdated ⇒ Object
readonly
Returns the value of attribute lastUpdated.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#networkId ⇒ Object
readonly
Returns the value of attribute networkId.
-
#overview ⇒ Object
readonly
Returns the value of attribute overview.
-
#rating ⇒ Object
readonly
Returns the value of attribute rating.
-
#runtime ⇒ Object
readonly
Returns the value of attribute runtime.
-
#seriesId ⇒ Object
readonly
Returns the value of attribute seriesId.
-
#seriesName ⇒ Object
(also: #name)
readonly
Returns the value of attribute seriesName.
-
#siteRating ⇒ Object
readonly
Returns the value of attribute siteRating.
-
#siteRatingCount ⇒ Object
readonly
Returns the value of attribute siteRatingCount.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#zap2itId ⇒ Object
readonly
Returns the value of attribute zap2itId.
Instance Method Summary to retrieve images collapse
-
#banner_url(random: false) ⇒ String
The banner image url of the series.
-
#banners ⇒ Array<TvdbStruct>
The list of banner images of the series.
-
#fanarts ⇒ Array<TvdbStruct>
The list of fanart images.
-
#images(params) ⇒ Array<TvdbStruct>
Retrieve the images of the series.
-
#images_summary ⇒ Array<TvdbStruct>
The image summary of the series.
-
#poster_url(random: false) ⇒ String
The poster image url of the series.
-
#posters ⇒ Array<TvdbStruct>
The list of poster images.
-
#season_images(season: nil) ⇒ Array<TvdbStruct>
The list of season images.
-
#seasonwide_images(season: nil) ⇒ Array<TvdbStruct>
The list of season wide images.
Instance Method Summary collapse
-
#[](index) ⇒ Episode
Get the episode of the series identified by the index.
-
#actors ⇒ Array<TvdbStruct>
The list of actors in the series.
-
#episodes(params = {}) ⇒ Array<Episode>
Retrieve the episodes of the series.
-
#initialize(client, data = {}) ⇒ Series
constructor
A new instance of Series.
-
#series_summary ⇒ TvdbStruct
(also: #summary)
Return the summary of the series.
-
#to_h(episodes: false, retrieve_all_fields: false) ⇒ Hash
The series to hash.
Constructor Details
#initialize(client, data = {}) ⇒ Series
The Tvdb2::Series object may not have all fields filled because it can be
initialized from not completed data like when is build from the call
API#search (GET /search/series
): in this case the api
call return a subset of all avaiable data for the series (INDEX_FIELDS).
But no warries! When you call a method to get one SHOW_FIELDS the library
automatically call the endpoint GET /series/{id}
to retrieve
the missing fields.
You should never need to create this object manually.
Returns a new instance of Series
64 65 66 67 68 69 70 |
# File 'lib/tvdb2/series.rb', line 64 def initialize(client, data = {}) @client = client FIELDS.each do |field| instance_variable_set("@#{field}", data[field.to_s]) end @completed = {@client.language => data.key?('added')} end |
Instance Attribute Details
#added ⇒ Object (readonly)
Returns the value of attribute added
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def added @added end |
#airsDayOfWeek ⇒ Object (readonly)
Returns the value of attribute airsDayOfWeek
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def airsDayOfWeek @airsDayOfWeek end |
#airsTime ⇒ Object (readonly)
Returns the value of attribute airsTime
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def airsTime @airsTime end |
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def aliases @aliases end |
#banner ⇒ Object (readonly)
Returns the value of attribute banner
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def @banner end |
#firstAired ⇒ Object (readonly)
Returns the value of attribute firstAired
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def firstAired @firstAired end |
#genre ⇒ Object (readonly)
Returns the value of attribute genre
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def genre @genre end |
#id ⇒ Object (readonly)
Returns the value of attribute id
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def id @id end |
#imdbId ⇒ Object (readonly)
Returns the value of attribute imdbId
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def imdbId @imdbId end |
#lastUpdated ⇒ Object (readonly)
Returns the value of attribute lastUpdated
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def lastUpdated @lastUpdated end |
#network ⇒ Object (readonly)
Returns the value of attribute network
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def network @network end |
#networkId ⇒ Object (readonly)
Returns the value of attribute networkId
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def networkId @networkId end |
#overview ⇒ Object (readonly)
Returns the value of attribute overview
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def overview @overview end |
#rating ⇒ Object (readonly)
Returns the value of attribute rating
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def @rating end |
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def runtime @runtime end |
#seriesId ⇒ Object (readonly)
Returns the value of attribute seriesId
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def seriesId @seriesId end |
#seriesName ⇒ Object (readonly) Also known as: name
Returns the value of attribute seriesName
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def seriesName @seriesName end |
#siteRating ⇒ Object (readonly)
Returns the value of attribute siteRating
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def siteRating @siteRating end |
#siteRatingCount ⇒ Object (readonly)
Returns the value of attribute siteRatingCount
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def siteRatingCount @siteRatingCount end |
#status ⇒ Object (readonly)
Returns the value of attribute status
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def status @status end |
#zap2itId ⇒ Object (readonly)
Returns the value of attribute zap2itId
23 24 25 |
# File 'lib/tvdb2/series.rb', line 23 def zap2itId @zap2itId end |
Instance Method Details
#[](index) ⇒ Episode
Get the episode of the series identified by the index.
116 117 118 119 120 121 122 123 124 |
# File 'lib/tvdb2/series.rb', line 116 def [](index) episodes = self.episodes if index.is_a?(Integer) return episodes.select{|e| e.absoluteNumber == index}.first else series, ep = index.split('x') return episodes.select{|e| e.airedSeason == series.to_i && e.airedEpisodeNumber == ep.to_i}.first end end |
#actors ⇒ Array<TvdbStruct>
Returns the list of actors in the series.
101 102 103 |
# File 'lib/tvdb2/series.rb', line 101 def actors @client.actors(self.id) end |
#banner_url(random: false) ⇒ String
Returns the banner image url of the series.
190 191 192 193 194 195 196 197 |
# File 'lib/tvdb2/series.rb', line 190 def (random: false) if random b = self..shuffle.first b ? b.url : nil else @banner ? Client.image_url(@banner) : nil end end |
#banners ⇒ Array<TvdbStruct>
Returns the list of banner images of the series.
183 184 185 |
# File 'lib/tvdb2/series.rb', line 183 def self.images(keyType: 'series') end |
#episodes(params = {}) ⇒ Array<Episode>
Retrieve the episodes of the series.
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/tvdb2/series.rb', line 85 def episodes(params = {}) return @client.episodes(self.id, params) if params && params.key?(:page) episodes = [] page = 1 loop do params.merge!(page: page) result = @client.episodes(self.id, params) episodes += result page += 1 break if result.size < 100 end return episodes.sort_by{|x| [x.airedSeason, x.airedEpisodeNumber]} end |
#fanarts ⇒ Array<TvdbStruct>
Returns the list of fanart images.
150 151 152 |
# File 'lib/tvdb2/series.rb', line 150 def fanarts self.images(keyType: 'fanart') end |
#images(params) ⇒ Array<TvdbStruct>
Retrieve the images of the series.
144 145 146 |
# File 'lib/tvdb2/series.rb', line 144 def images(params) @client.images(self.id, params) end |
#images_summary ⇒ Array<TvdbStruct>
Returns the image summary of the series.
130 131 132 |
# File 'lib/tvdb2/series.rb', line 130 def images_summary @client.images_summary(self.id) end |
#poster_url(random: false) ⇒ String
Returns the poster image url of the series.
202 203 204 205 206 |
# File 'lib/tvdb2/series.rb', line 202 def poster_url(random: false) ps = self.posters ps.shuffle! if random ps.first ? ps.first.url : nil end |
#posters ⇒ Array<TvdbStruct>
Returns the list of poster images.
156 157 158 |
# File 'lib/tvdb2/series.rb', line 156 def posters self.images(keyType: 'poster') end |
#season_images(season: nil) ⇒ Array<TvdbStruct>
Returns the list of season images.
164 165 166 167 168 |
# File 'lib/tvdb2/series.rb', line 164 def season_images(season: nil) r = self.images(keyType: 'season') r.select!{|x| x.subKey == season.to_s} if season r.sort{|x,y| x.subKey <=> y.subKey} end |
#seasonwide_images(season: nil) ⇒ Array<TvdbStruct>
Returns the list of season wide images.
174 175 176 177 178 |
# File 'lib/tvdb2/series.rb', line 174 def seasonwide_images(season: nil) r = self.images(keyType: 'seasonwide') r.select!{|x| x.subKey == season.to_s} if season r.sort{|x,y| x.subKey <=> y.subKey} end |
#series_summary ⇒ TvdbStruct Also known as: summary
Return the summary of the series.
74 75 76 |
# File 'lib/tvdb2/series.rb', line 74 def series_summary @client.series_summary(self.id) end |
#to_h(episodes: false, retrieve_all_fields: false) ⇒ Hash
Returns the series to hash.
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/tvdb2/series.rb', line 215 def to_h(episodes: false, retrieve_all_fields: false) get_all_fields! if retrieve_all_fields hash = {} FIELDS.each do |field| hash[field.to_sym] = instance_variable_get("@#{field}") end hash[:name] = @seriesName hash[:poster_url] = self.poster_url hash[:banner_url] = self. hash[:episodes] = self.episodes.map(&:to_h) if episodes return hash end |