Class: Base::Api::Show

Inherits:
Object show all
Extended by:
Helpers
Includes:
Helpers
Defined in:
lib/base/api/show.rb

Direct Known Subclasses

TheTvDb::Api::Show, TvRage::Api::Show

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

get_remote_file_as_string, parsable_date?, safely_parse_date

Constructor Details

#initialize(xml_document) ⇒ Show

Returns a new instance of Show.



16
17
18
19
# File 'lib/base/api/show.rb', line 16

def initialize(xml_document)
  @xml_doc = xml_document
  self
end

Instance Attribute Details

#networkObject

Returns the value of attribute network.



14
15
16
# File 'lib/base/api/show.rb', line 14

def network
  @network
end

#xml_docObject

Returns the value of attribute xml_doc.



14
15
16
# File 'lib/base/api/show.rb', line 14

def xml_doc
  @xml_doc
end

Class Method Details

.find(name_or_id) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/base/api/show.rb', line 87

def find(name_or_id)
  if name_or_id.is_a?(String)
    find_by_name(name_or_id)
  elsif name_or_id.is_a?(Integer)
    find_by_id(name_or_id)
  end
end

.search_xml_document(series_name) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/base/api/show.rb', line 116

def search_xml_document(series_name)
  if string = search_xml_string(series_name)
    document = Nokogiri::XML(string, 'UTF-8')
    if not document.root.nil?  
      document
    else
      raise UnprocessableXMLError
    end
  else
    raise RemoteDocumentRetrivalError
  end
end

.search_xml_string(series_name) ⇒ Object



99
100
101
# File 'lib/base/api/show.rb', line 99

def search_xml_string(series_name)
  get_remote_file_as_string(search_url_for(series_name))
end

.xml_document(series_id) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/base/api/show.rb', line 103

def xml_document(series_id)
  if string = xml_string(series_id)
    document = Nokogiri::XML(string, 'UTF-8')
    if not document.root.nil?
      document
    else
      raise UnprocessableXMLError
    end
  else
   raise RemoteDocumentRetrievalError
  end
end

.xml_string(series_id) ⇒ Object



95
96
97
# File 'lib/base/api/show.rb', line 95

def xml_string(series_id)
  get_remote_file_as_string(url_for(series_id))
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/base/api/show.rb', line 39

def ==(other)
  attributes == other.attributes
end

#actorsObject



53
# File 'lib/base/api/show.rb', line 53

def actors;         []; end

#air_datesObject



54
# File 'lib/base/api/show.rb', line 54

def air_dates;      []; end

#aliasesObject



55
# File 'lib/base/api/show.rb', line 55

def aliases;        []; end

#attributesObject

Returns a list of attribute hashes, from the Show calls internal lookup methods, always a hash



29
30
31
32
33
34
35
36
37
# File 'lib/base/api/show.rb', line 29

def attributes
  {
    name:     name,
    country:  country,
    started:  started,
    overview: overview,
    status:   status
  }
end

#classificationObject



60
# File 'lib/base/api/show.rb', line 60

def classification; nil; end

#countryObject



61
# File 'lib/base/api/show.rb', line 61

def country;        nil; end

#genresObject



56
# File 'lib/base/api/show.rb', line 56

def genres;         []; end

#languageObject



62
# File 'lib/base/api/show.rb', line 62

def language;       nil; end

#nameObject



43
44
45
46
47
48
49
50
51
# File 'lib/base/api/show.rb', line 43

def name
  if original_name_contains_bracketed_year?
    original_name.gsub(/\(\d{4}\)/, '').strip
  elsif original_name_contains_bracketed_country?
    original_name.gsub(/\([A-Z]{2,3}\)/, '').strip
  else
    original_name
  end
end

#network_idObject

Raises:

  • (NotImplementedErorr)


69
# File 'lib/base/api/show.rb', line 69

def network_id;     raise NotImplementedErorr; end

#original_nameObject



64
# File 'lib/base/api/show.rb', line 64

def original_name;  nil; end

#overviewObject



65
# File 'lib/base/api/show.rb', line 65

def overview;       nil; end

#remote_idsObject



57
# File 'lib/base/api/show.rb', line 57

def remote_ids;     []; end

#runtimeObject



66
# File 'lib/base/api/show.rb', line 66

def runtime;        nil; end

#startedObject



67
# File 'lib/base/api/show.rb', line 67

def started;        nil; end

#statusObject



58
# File 'lib/base/api/show.rb', line 58

def status;         []; end

#to_sObject



21
22
23
# File 'lib/base/api/show.rb', line 21

def to_s
  "#{self.class} #{name}"
end