Class: Tvdb2::Episode

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

Overview

This class rappresent a series episode retrieved from TVDB api.

Constant Summary

INDEX_FIELDS =

Fields returned from api endpoint GET /series/{id}/episodes

[
  :absoluteNumber, :airedEpisodeNumber, :airedSeason,:dvdEpisodeNumber,
  :dvdSeason, :episodeName, :firstAired, :id, :lastUpdated, :overview
]
SHOW_FIELDS =

Other fields with INDEX_FIELDS returned from api endpoint GET /episodes/{id}

[
  :airsAfterSeason, :airsBeforeEpisode, :airsBeforeSeason, :direcotor,
  :directors, :dvdChapter, :dvdDiscid, :filename, :guestStars, :imdbId,
  :lastUpdatedBy, :productionCode, :seriesId, :showUrl, :siteRating,
  :siteRatingCount, :thumbAdded, :thumbAuthor, :thumbHeight, :thumbWidth,
  :writers
]
FIELDS =

All possible data fields returned from api for a series.

INDEX_FIELDS + SHOW_FIELDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data = {}) ⇒ Episode

Note:

The Tvdb2::Episode object may not have all fields filled because it can be initialized from not completed data like when is build from the call Series#episodes (GET /series/{id}/episodes): in this case the api call return a subset of all avaiable data for the episodes (INDEX_FIELDS). But no warries! When you call a method to get one SHOW_FIELDS the library automatically call the endpoint GET /episodes/{id} to retrieve the missing fields.

Note:

You should never need to create this object manually.

Returns a new instance of Episode

Parameters:

  • client (Client)

    a TVDB api client.

  • data (Hash) (defaults to: {})

    the data retrieved from api.



68
69
70
71
72
73
74
# File 'lib/tvdb2/episode.rb', line 68

def initialize(client, data = {})
  @client = client
  FIELDS.each do |field|
    instance_variable_set("@#{field}", data[field.to_s])
  end
  @completed = {@client.language => data.key?('seriesId')}
end

Instance Attribute Details

#absoluteNumberObject (readonly)

Returns the value of attribute absoluteNumber



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def absoluteNumber
  @absoluteNumber
end

#airedEpisodeNumberObject (readonly) Also known as: number

Returns the value of attribute airedEpisodeNumber



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def airedEpisodeNumber
  @airedEpisodeNumber
end

#airedSeasonObject (readonly) Also known as: seasonNumber

Returns the value of attribute airedSeason



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def airedSeason
  @airedSeason
end

#airsAfterSeasonObject (readonly)

Returns the value of attribute airsAfterSeason



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def airsAfterSeason
  @airsAfterSeason
end

#airsBeforeEpisodeObject (readonly)

Returns the value of attribute airsBeforeEpisode



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def airsBeforeEpisode
  @airsBeforeEpisode
end

#airsBeforeSeasonObject (readonly)

Returns the value of attribute airsBeforeSeason



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def airsBeforeSeason
  @airsBeforeSeason
end

#direcotorObject (readonly)

Returns the value of attribute direcotor



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def direcotor
  @direcotor
end

#directorsObject (readonly)

Returns the value of attribute directors



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def directors
  @directors
end

#dvdChapterObject (readonly)

Returns the value of attribute dvdChapter



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def dvdChapter
  @dvdChapter
end

#dvdDiscidObject (readonly)

Returns the value of attribute dvdDiscid



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def dvdDiscid
  @dvdDiscid
end

#dvdEpisodeNumberObject (readonly)

Returns the value of attribute dvdEpisodeNumber



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def dvdEpisodeNumber
  @dvdEpisodeNumber
end

#dvdSeasonObject (readonly)

Returns the value of attribute dvdSeason



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def dvdSeason
  @dvdSeason
end

#episodeNameObject (readonly) Also known as: name

Returns the value of attribute episodeName



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def episodeName
  @episodeName
end

#filenameObject (readonly)

Returns the value of attribute filename



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def filename
  @filename
end

#firstAiredObject (readonly)

Returns the value of attribute firstAired



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def firstAired
  @firstAired
end

#guestStarsObject (readonly)

Returns the value of attribute guestStars



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def guestStars
  @guestStars
end

#idObject (readonly)

Returns the value of attribute id



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def id
  @id
end

#imdbIdObject (readonly)

Returns the value of attribute imdbId



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def imdbId
  @imdbId
end

#lastUpdatedObject (readonly)

Returns the value of attribute lastUpdated



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def lastUpdated
  @lastUpdated
end

#lastUpdatedByObject (readonly)

Returns the value of attribute lastUpdatedBy



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def lastUpdatedBy
  @lastUpdatedBy
end

#overviewObject (readonly)

Returns the value of attribute overview



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def overview
  @overview
end

#productionCodeObject (readonly)

Returns the value of attribute productionCode



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def productionCode
  @productionCode
end

#seriesIdObject (readonly)

Returns the value of attribute seriesId



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def seriesId
  @seriesId
end

#showUrlObject (readonly)

Returns the value of attribute showUrl



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def showUrl
  @showUrl
end

#siteRatingObject (readonly)

Returns the value of attribute siteRating



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def siteRating
  @siteRating
end

#siteRatingCountObject (readonly)

Returns the value of attribute siteRatingCount



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def siteRatingCount
  @siteRatingCount
end

#thumbAddedObject (readonly)

Returns the value of attribute thumbAdded



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def thumbAdded
  @thumbAdded
end

#thumbAuthorObject (readonly)

Returns the value of attribute thumbAuthor



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def thumbAuthor
  @thumbAuthor
end

#thumbHeightObject (readonly)

Returns the value of attribute thumbHeight



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def thumbHeight
  @thumbHeight
end

#thumbWidthObject (readonly)

Returns the value of attribute thumbWidth



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def thumbWidth
  @thumbWidth
end

#writersObject (readonly)

Returns the value of attribute writers



25
26
27
# File 'lib/tvdb2/episode.rb', line 25

def writers
  @writers
end

Instance Method Details

#to_h(retrieve_all_fields: false) ⇒ Hash

Returns the episode to hash.

Parameters:

  • retrieve_all_fields (Boolean)

    if true retrieve all fields (from api) of the episode.

Returns:

  • (Hash)

    the episode to hash.



85
86
87
88
89
90
91
92
93
# File 'lib/tvdb2/episode.rb', line 85

def to_h(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] = @episodeName
  return hash
end

#xString

Returns the episode number with the “x” syntax: "#{season_number}x#{episode_number} (3x9)“.

Returns:

  • (String)

    the episode number with the “x” syntax: "#{season_number}x#{episode_number} (3x9)“.



78
79
80
# File 'lib/tvdb2/episode.rb', line 78

def x
  "#{self.airedSeason}x#{self.airedEpisodeNumber}"
end