Class: TheTvDB::Series
- Inherits:
-
API
- Object
- API
- TheTvDB::Series
show all
- Includes:
- Model
- Defined in:
- lib/the_tv_db/series.rb
Defined Under Namespace
Classes: Collection
Constant Summary
collapse
- ATTRS_MAP =
{
:id => "id",
:actors => "Actors",
:added => "added",
:added_by => "addedBy",
:airs_day_of_week => "Airs_DayOfWeek",
:airs_time => "Airs_Time",
:banner => "banner",
:content_rating => "ContentRating",
:fanart => "fanart",
:first_aired => "FirstAired",
:genre => "Genre",
:imdb_id => "IMDB_ID",
:language => "Language",
:last_updated => "lastupdated",
:network => "Network",
:network_id => "NetworkID",
:overview => "Overview",
:rating => "Rating",
:rating_count => "RatingCount",
:runtime => "Runtime",
:poster => "poster",
:series_id => "SeriesID",
:series_name => "SeriesName",
:status => "Status",
:zap2it_id => "zap2it_id"
}.freeze
Instance Attribute Summary
Attributes included from Model
#klass
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Model
#attribute_for_inspect, #attributes, #attributes=, #attributes_map, #class_attributes, #initialize, #inspect
Methods inherited from API
#initialize, #set_api_client
Methods included from Connection
#connection, #request
Class Method Details
.find(id, lang = "en") ⇒ Object
Also known as:
get
52
53
54
55
|
# File 'lib/the_tv_db/series.rb', line 52
def find(id, lang="en")
format = TheTvDB.api_key ? :zip : :xml
send("get_#{format}_by_id", id, lang)
end
|
.search(name, lang = "en") ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/the_tv_db/series.rb', line 36
def search(name, lang="en")
data = request("GetSeries.php", { seriesname: name, language: lang })["Data"]
return [] if data.nil?
series = data["Series"]
case series
when Hash
[ Series::Collection.new(series) ]
when Array
series.collect { |serie| Series::Collection.new(serie) }
else
[]
end
end
|
Instance Method Details
#build_actors_from_xml(doc) ⇒ Object
95
96
97
|
# File 'lib/the_tv_db/series.rb', line 95
def build_actors_from_xml(doc)
build_association_from_xml(:actors, doc)
end
|
#build_association_from_xml(association_name, doc) ⇒ Object
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/the_tv_db/series.rb', line 99
def build_association_from_xml(association_name, doc)
name_for_collection = association_name.to_s.capitalize
name_for_element = name_for_collection[0..-2]
elements = if doc && doc[name_for_collection]
doc[name_for_collection][name_for_element]
end
self.send("#{association_name}=", elements)
end
|
#build_banners_from_xml(doc) ⇒ Object
91
92
93
|
# File 'lib/the_tv_db/series.rb', line 91
def build_banners_from_xml(doc)
build_association_from_xml(:banners, doc)
end
|
#episodes=(episodes) ⇒ Object
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/the_tv_db/series.rb', line 80
def episodes=(episodes)
@episodes = case episodes
when Hash
[ Episode.new(episodes) ]
when Array
episodes.collect { |episode| Episode.new(episode) }
else
[]
end
end
|