Class: TVDB::Series

Inherits:
Object
  • Object
show all
Defined in:
lib/tvdb-rb/series.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, xml, detailed_response) ⇒ Series

Returns a new instance of Series.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tvdb-rb/series.rb', line 19

def initialize client, xml, detailed_response
  @client = client
  # @raw_rsp = xml
  @series_id = xml.xpath("seriesid").text
  @language = xml.xpath("language").text
  @series_name = xml.xpath("SeriesName").text
  @banner = xml.xpath("banner").text
  @overview = xml.xpath("Overview").text
  @first_aired = xml.xpath("FirstAired").text #Date.parse?
  @imdb_id = xml.xpath("IMDB_ID").text
  @tvdb_id = xml.xpath("id").text
  @api_url = "#{client.api_endpoint}/series/#{series_id}"
  load_detail if detailed_response
end

Instance Attribute Details

#actorsObject

Returns the value of attribute actors.



15
16
17
# File 'lib/tvdb-rb/series.rb', line 15

def actors
  @actors
end

Returns the value of attribute banner.



8
9
10
# File 'lib/tvdb-rb/series.rb', line 8

def banner
  @banner
end

#first_airedObject

Returns the value of attribute first_aired.



10
11
12
# File 'lib/tvdb-rb/series.rb', line 10

def first_aired
  @first_aired
end

#genresObject

detailed response



14
15
16
# File 'lib/tvdb-rb/series.rb', line 14

def genres
  @genres
end

#imdb_idObject

Returns the value of attribute imdb_id.



11
12
13
# File 'lib/tvdb-rb/series.rb', line 11

def imdb_id
  @imdb_id
end

#languageObject

Returns the value of attribute language.



6
7
8
# File 'lib/tvdb-rb/series.rb', line 6

def language
  @language
end

#overviewObject

Returns the value of attribute overview.



9
10
11
# File 'lib/tvdb-rb/series.rb', line 9

def overview
  @overview
end

#ratingObject

Returns the value of attribute rating.



16
17
18
# File 'lib/tvdb-rb/series.rb', line 16

def rating
  @rating
end

#rating_countObject

Returns the value of attribute rating_count.



17
18
19
# File 'lib/tvdb-rb/series.rb', line 17

def rating_count
  @rating_count
end

#series_idObject

Returns the value of attribute series_id.



5
6
7
# File 'lib/tvdb-rb/series.rb', line 5

def series_id
  @series_id
end

#series_nameObject

Returns the value of attribute series_name.



7
8
9
# File 'lib/tvdb-rb/series.rb', line 7

def series_name
  @series_name
end

#tvdb_idObject

Returns the value of attribute tvdb_id.



12
13
14
# File 'lib/tvdb-rb/series.rb', line 12

def tvdb_id
  @tvdb_id
end

Instance Method Details

#episodesObject



56
57
58
# File 'lib/tvdb-rb/series.rb', line 56

def episodes
  @episodes ||= get_episodes
end

#get_episode(season_number, episode_number) ⇒ Object



52
53
54
# File 'lib/tvdb-rb/series.rb', line 52

def get_episode season_number, episode_number
  episodes.find{|e| e.episode_number == episode_number && e.season_number == season_number }
end

#get_episodesObject



43
44
45
46
47
48
49
50
# File 'lib/tvdb-rb/series.rb', line 43

def get_episodes
  xml = Nokogiri::XML RestClient.get "#{@api_url}/all"
  episode_array = []
  xml.xpath("//Episode").each do |episode_xml|
    episode_array << Episode.new(@client, episode_xml)
  end
  Episodes.new(episode_array)
end

#load_detailObject



34
35
36
37
38
39
40
41
# File 'lib/tvdb-rb/series.rb', line 34

def load_detail
  xml = Nokogiri::XML RestClient.get @api_url
  root = xml.xpath("Data/Series")
  @genres = to_array root.xpath("Genre").text
  @actors = to_array root.xpath("Actors").text
  @rating = root.xpath("Rating").text
  @rating_count = root.xpath("RatingCount").text
end

#to_array(string) ⇒ Object



60
61
62
# File 'lib/tvdb-rb/series.rb', line 60

def to_array string
  string.split("|").reject! { |c| c.empty? }
end