Class: Plex::Season

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

Overview

Found at /library/metadata/:key

Constant Summary collapse

ATTRIBUTES =
%w(ratingKey guid type title summary index thumb leafCount
viewedLeafCount addedAt updatedAt)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(show, key) ⇒ Season

Returns a new instance of Season.

Parameters:

  • show (Show)

    this Season belongs to

  • key (String)

    to later grab this Season from



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

def initialize(show, key)
  @show = show
  @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::Season##{Plex.underscore(method+'!')} IS DEPRECATED! Use Plex::Season##{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/season.rb', line 8

def attribute_hash
  @attribute_hash
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#showObject (readonly)

Returns the value of attribute show.



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

def show
  @show
end

Instance Method Details

#==(other) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/plex-ruby/season.rb', line 66

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

#episode(number) ⇒ Episode

Select a particular episode

Parameters:

  • episode (Fixnum, String)

    index number

Returns:

  • (Episode)

    episode with the index of number



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

def episode(number)
  episodes.detect { |epi| epi.index.to_i == number.to_i }
end

#episodesArray

Returns the list of episodes in the library that are a part of this Season

Returns:

  • (Array)

    list of episodes in this season that are on the server



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

def episodes
  @episodes ||= episodes_from_video(children)
end

#first_episodeEpisode

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

Returns:

  • (Episode)

    episode with the lowest index



49
50
51
# File 'lib/plex-ruby/season.rb', line 49

def first_episode
  episodes.min_by { |e| e.index.to_i }
end

#inspectObject



75
76
77
# File 'lib/plex-ruby/season.rb', line 75

def inspect #:nodoc:
  "#<Plex::Season: key=\"#{key}\" title=\"#{title}\" index=\"#{index}\" show=\"#{show.title}\">"
end

#last_episodeEpisode

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

Returns:

  • (Episode)

    episode with the highest index



56
57
58
# File 'lib/plex-ruby/season.rb', line 56

def last_episode
  episodes.max_by { |e| e.index.to_i }
end

#urlObject



61
62
63
# File 'lib/plex-ruby/season.rb', line 61

def url #:nodoc:
  show.url
end