Class: Tvrage::Tvshow

Inherits:
Object
  • Object
show all
Defined in:
lib/tvrage/tvshow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Tvshow

Returns a new instance of Tvshow.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tvrage/tvshow.rb', line 7

def initialize(data)
  @id = data.xpath('showid').text.to_i
  @name = data.xpath('name').text
  @season_count = data.xpath('totalseasons').text.to_i
  @image = data.xpath('image').text
  @country = data.xpath('origin_country').text
  @link = data.xpath('link').text
  @status = data.xpath('status').text
  @classification = data.xpath('classification').text
  @runtime = data.xpath('runtime').text.to_i
  @network = data.xpath('network').text
  @air_day = data.xpath('air_day').text
  @timezone = data.xpath('timezone').text
  @link = data.xpath('showlink').text
  
  begin
    @air_time = Time.parse(data.xpath('airtime').text) if !data.xpath('airtime').text.empty?
  rescue Exception => e
    # invalid air time
  end
  
  @genres = data.xpath('genres/genre').map { |g| g.text } if data.xpath('genres/genre').length > 0
  @genres.reject! { |g| g.empty? } unless @genres.nil?
  
  begin
    @started = Date.parse(data.xpath('started').text) if !data.xpath('started').text.empty?
  rescue Exception => e
    # invalid start date
  end

  begin
    @ended = Date.parse(data.xpath('ended').text) if !data.xpath('ended').text.empty?
  rescue Exception => e
    # invalid end date
  end

  @episodes = data.xpath('Episodelist//Season/episode').map { |e| Episode.new(e, e.parent['no']) }
end

Instance Attribute Details

#air_dayObject

Returns the value of attribute air_day.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def air_day
  @air_day
end

#air_timeObject

Returns the value of attribute air_time.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def air_time
  @air_time
end

#classificationObject

Returns the value of attribute classification.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def classification
  @classification
end

#countryObject

Returns the value of attribute country.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def country
  @country
end

#endedObject

Returns the value of attribute ended.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def ended
  @ended
end

#episodesObject

Returns the value of attribute episodes.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def episodes
  @episodes
end

#genresObject

Returns the value of attribute genres.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def genres
  @genres
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def id
  @id
end

#imageObject

Returns the value of attribute image.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def image
  @image
end

Returns the value of attribute link.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def link
  @link
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def name
  @name
end

#networkObject

Returns the value of attribute network.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def network
  @network
end

#runtimeObject

Returns the value of attribute runtime.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def runtime
  @runtime
end

#season_countObject

Returns the value of attribute season_count.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def season_count
  @season_count
end

#seasonsObject

Returns the value of attribute seasons.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def seasons
  @seasons
end

#startedObject

Returns the value of attribute started.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def started
  @started
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def status
  @status
end

#timezoneObject

Returns the value of attribute timezone.



5
6
7
# File 'lib/tvrage/tvshow.rb', line 5

def timezone
  @timezone
end