Class: P3::Tvdb::Episode

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, options = {}) ⇒ Episode

Returns a new instance of Episode.



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
# File 'lib/p3-tvdb/episode.rb', line 7

def initialize(client, options={})
    @client = client
    @id = options["id"]
    @season_number = options["SeasonNumber"].to_i
    @number = options["EpisodeNumber"].to_i
    @name = options["EpisodeName"]
    @overview = options["Overview"]
    @thumb = "http://thetvdb.com/banners/" + options["filename"] if options["filename"].to_s != ""
    @director = options["Director"]
    @writer = options["Writer"]
    @series_id = options["seriesid"]
    @rating_count = options["RatingCount"]
    if options["GuestStars"]
        @guest_stars = options["GuestStars"][1..-1].split("|")
    else
        @guest_stars = []
    end

    if options["Rating"] && options["Rating"].size > 0
        @rating = options["Rating"].to_f
    else
        @rating = 0
    end

    if options["RatingCount"] && options["RatingCount"].size > 0
        @rating_count = options["RatingCount"].to_f
    else
        @rating_count = 0
    end

    begin
        @air_date = Date.parse(options["FirstAired"])
    rescue
    end
end

Instance Attribute Details

#air_dateObject

Returns the value of attribute air_date.



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

def air_date
  @air_date
end

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/p3-tvdb/episode.rb', line 4

def client
  @client
end

#directorObject

Returns the value of attribute director.



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

def director
  @director
end

#guest_starsObject

Returns the value of attribute guest_stars.



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

def guest_stars
  @guest_stars
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#overviewObject

Returns the value of attribute overview.



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

def overview
  @overview
end

#ratingObject

Returns the value of attribute rating.



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

def rating
  @rating
end

#rating_countObject

Returns the value of attribute rating_count.



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

def rating_count
  @rating_count
end

#season_numberObject

Returns the value of attribute season_number.



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

def season_number
  @season_number
end

#thumbObject

Returns the value of attribute thumb.



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

def thumb
  @thumb
end

#writerObject

Returns the value of attribute writer.



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

def writer
  @writer
end

Instance Method Details

#seriesObject



43
44
45
# File 'lib/p3-tvdb/episode.rb', line 43

def series
    client.get_series_by_id(@series_id)
end

#to_hObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/p3-tvdb/episode.rb', line 47

def to_h
    hash = {}
    self.instance_variables.each do | var |
        #turn episode object into hash
        v = self.instance_variable_get( var )
        hash[ var.to_s.gsub('@','').to_sym ] = v
    end
    hash.delete(:client)
    return hash
end