Class: TVDB::Series
- Inherits:
-
Object
- Object
- TVDB::Series
- Defined in:
- lib/tvdb-rb/series.rb
Instance Attribute Summary collapse
-
#actors ⇒ Object
Returns the value of attribute actors.
-
#banner ⇒ Object
Returns the value of attribute banner.
-
#first_aired ⇒ Object
Returns the value of attribute first_aired.
-
#genres ⇒ Object
detailed response.
-
#imdb_id ⇒ Object
Returns the value of attribute imdb_id.
-
#language ⇒ Object
Returns the value of attribute language.
-
#overview ⇒ Object
Returns the value of attribute overview.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#rating_count ⇒ Object
Returns the value of attribute rating_count.
-
#series_id ⇒ Object
Returns the value of attribute series_id.
-
#series_name ⇒ Object
Returns the value of attribute series_name.
-
#tvdb_id ⇒ Object
Returns the value of attribute tvdb_id.
Instance Method Summary collapse
- #episodes ⇒ Object
- #get_episode(season_number, episode_number) ⇒ Object
- #get_episodes ⇒ Object
-
#initialize(client, xml, detailed_response) ⇒ Series
constructor
A new instance of Series.
- #load_detail ⇒ Object
- #to_array(string) ⇒ Object
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
#actors ⇒ Object
Returns the value of attribute actors.
15 16 17 |
# File 'lib/tvdb-rb/series.rb', line 15 def actors @actors end |
#banner ⇒ Object
Returns the value of attribute banner.
8 9 10 |
# File 'lib/tvdb-rb/series.rb', line 8 def @banner end |
#first_aired ⇒ Object
Returns the value of attribute first_aired.
10 11 12 |
# File 'lib/tvdb-rb/series.rb', line 10 def first_aired @first_aired end |
#genres ⇒ Object
detailed response
14 15 16 |
# File 'lib/tvdb-rb/series.rb', line 14 def genres @genres end |
#imdb_id ⇒ Object
Returns the value of attribute imdb_id.
11 12 13 |
# File 'lib/tvdb-rb/series.rb', line 11 def imdb_id @imdb_id end |
#language ⇒ Object
Returns the value of attribute language.
6 7 8 |
# File 'lib/tvdb-rb/series.rb', line 6 def language @language end |
#overview ⇒ Object
Returns the value of attribute overview.
9 10 11 |
# File 'lib/tvdb-rb/series.rb', line 9 def overview @overview end |
#rating ⇒ Object
Returns the value of attribute rating.
16 17 18 |
# File 'lib/tvdb-rb/series.rb', line 16 def @rating end |
#rating_count ⇒ Object
Returns the value of attribute rating_count.
17 18 19 |
# File 'lib/tvdb-rb/series.rb', line 17 def @rating_count end |
#series_id ⇒ Object
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_name ⇒ Object
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_id ⇒ Object
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
#episodes ⇒ Object
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_episodes ⇒ Object
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_detail ⇒ Object
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 |