Class: Plex::Show

Inherits:
Object
  • Object
show all
Defined in:
lib/plex-ruby/show.rb

Constant Summary collapse

ATTRIBUTES =
%w(ratingKey guid studio type title contentRating summary index
rating year thumb art leafCount viewedLeafCount addedAt
updatedAt)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(section, key) ⇒ Show

Returns a new instance of Show.

Parameters:

  • section (Section)

    this show belongs to

  • key (String)

    to use to later grab this Show


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/plex-ruby/show.rb', line 12

def initialize(section, key)
  @section = section
  @key = key
  @attribute_hash = {}

  directory.attributes.each do |method, val|
    @attribute_hash[Plex.underscore(method)] = val.value
    define_singleton_method(Plex.underscore(method).to_sym) do
      val.value
    end
    define_singleton_method(Plex.underscore(method+'!').to_sym) do
      puts "Plex::Show##{Plex.underscore(method+'!')} IS DEPRECATED! Use Plex::Show##{Plex.underscore(method)} instead."
      self.send(Plex.underscore(method))
    end
  end

  @attribute_hash.merge({'key' => @key})
end

Instance Attribute Details

#attribute_hashObject (readonly)

Returns the value of attribute attribute_hash


8
9
10
# File 'lib/plex-ruby/show.rb', line 8

def attribute_hash
  @attribute_hash
end

#keyObject (readonly)

Returns the value of attribute key


8
9
10
# File 'lib/plex-ruby/show.rb', line 8

def key
  @key
end

#sectionObject (readonly)

Returns the value of attribute section


8
9
10
# File 'lib/plex-ruby/show.rb', line 8

def section
  @section
end

Instance Method Details

#==(other) ⇒ Object


92
93
94
95
96
97
98
# File 'lib/plex-ruby/show.rb', line 92

def ==(other) #:nodoc:
  if other.is_a? Plex::Show
    key == other.key
  else
    super
  end
end

#first_episodeEpisode

Selects the first episode of this show that is on the Plex Server

Returns:

  • (Episode)

    episode with the lowest index of the season of the lowest index


74
75
76
# File 'lib/plex-ruby/show.rb', line 74

def first_episode
  first_season.first_episode
end

#first_seasonSeason

Selects the first season of this show that is on the Plex Server Does not select season 0

Returns:

  • (Season)

    season with the lowest index (but not 0)


59
60
61
# File 'lib/plex-ruby/show.rb', line 59

def first_season
  seasons.inject { |a, b| a.index.to_i < b.index.to_i && a.index.to_i > 0 ? a : b }
end

#inspectObject


101
102
103
# File 'lib/plex-ruby/show.rb', line 101

def inspect #:nodoc:
  "#<Plex::Show: key=\"#{key}\" title=\"#{title}\">"
end

#last_episodeEpisode

Selects the last episode of this show that is on the Plex Server

Returns:

  • (Episode)

    episode with the highest index of the season of the highest index


82
83
84
# File 'lib/plex-ruby/show.rb', line 82

def last_episode
  last_season.last_episode
end

#last_seasonSeason

Selects the last season of this show that is on the Plex Server

Returns:

  • (Season)

    season with the highest index


66
67
68
# File 'lib/plex-ruby/show.rb', line 66

def last_season
  seasons.max_by { |s| s.index.to_i }
end

#season(number) ⇒ Season

Select a particular season

Parameters:

  • season (Fixnum, String)

    index number

Returns:

  • (Season)

    season with the index of number


42
43
44
# File 'lib/plex-ruby/show.rb', line 42

def season(number)
  seasons.detect { |sea| sea.index.to_i == number.to_i }
end

#seasonsArray

The list of seasons in the library that belong to this Show

Returns:

  • (Array)

    list of Seasons that are a part of this Show


34
35
36
# File 'lib/plex-ruby/show.rb', line 34

def seasons
  @seasons ||= search_children children
end

#special_seasonSeason

Helper method for selecting the special Season of this show Season 0 is where Plex stores episodes that are not part of a regular season. i.e. Christmas Specials

Returns:

  • (Season)

    season with index of 0


51
52
53
# File 'lib/plex-ruby/show.rb', line 51

def special_season
  season(0)
end

#urlObject


87
88
89
# File 'lib/plex-ruby/show.rb', line 87

def url #:nodoc:
  section.url
end