Class: Addic7ed::Episode

Inherits:
Object
  • Object
show all
Defined in:
lib/addic7ed/models/episode.rb

Overview

Represents a TV sho episode.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(showname, season, episode) ⇒ Episode

Creates a new instance of Addic7ed::Episode.

Examples:

Addic7ed::Episode.new("Game of Thrones", 6, 9)
#=> #<Addic7ed::Episode
#       @episode=9,
#       @season=6,
#       @showname="Game.of.Thrones",
#       @subtitles={:fr=>nil, :ar=>nil, :az=>nil, ..., :th=>nil, :tr=>nil, :vi=>nil}
#    >

30
31
32
33
34
35
# File 'lib/addic7ed/models/episode.rb', line 30

def initialize(showname, season, episode)
  @showname  = showname
  @season    = season
  @episode   = episode
  @subtitles = languages_hash { |code, _| { code => nil } }
end

Instance Attribute Details

#episodeNumeric

Episode number in the season.


11
12
13
# File 'lib/addic7ed/models/episode.rb', line 11

def episode
  @episode
end

#seasonNumeric

Season number.


11
12
13
# File 'lib/addic7ed/models/episode.rb', line 11

def season
  @season
end

#shownameString

TV show name.


11
12
13
# File 'lib/addic7ed/models/episode.rb', line 11

def showname
  @showname
end

Instance Method Details

#page_url(language) ⇒ String

Returns the URL of the Addic7ed webpage listing subtitles for this Addic7ed::Episode in the given language.

Examples:

Addic7ed::Episode.new("Game of Thrones", 6, 9).page_url
#=> "http://www.addic7ed.com/serie/Game_of_Thrones/6/9/8"

90
91
92
# File 'lib/addic7ed/models/episode.rb', line 90

def page_url(language)
  localized_urls[language]
end

#subtitles(language) ⇒ Array<Subtitle>

Returns a list of all available Subtitles for this Addic7ed::Episode in the given language.

Examples:

Addic7ed::Episode.new("Game.of.Thrones", 3, 9).subtitles(:fr)
#=> [
#      #<Addic7ed::Subtitle
#          @comment="works with ctrlhd",
#          @downloads=28130,
#          @hi=false,
#          @language="French",
#          @source="http://addic7ed.com",
#          @status="Completed",
#          @url="http://www.addic7ed.com/updated/8/76081/0",
#          @version="EVOLVE">,
#      #<Addic7ed::Subtitle
#          @comment="la fabrique",
#          @downloads=1515,
#          @hi=false,
#          @language="French",
#          @source="http://sous-titres.eu",
#          @status="Completed",
#          @url="http://www.addic7ed.com/original/76081/11",
#          @version="EVOLVE">,
#      #<Addic7ed::Subtitle
#          @comment="la fabrique",
#          @downloads=917,
#          @hi=false,
#          @language="French",
#          @source="http://sous-titres.eu",
#          @status="Completed",
#          @url="http://www.addic7ed.com/original/76081/12",
#          @version="WEB,DL,NTB,&,YFN">
#     ]

75
76
77
# File 'lib/addic7ed/models/episode.rb', line 75

def subtitles(language)
  @subtitles[language] ||= Addic7ed::ParsePage.call(page_url(language))
end