Class: RubyTapasDownloader::Downloadables::Episode

Inherits:
RubyTapasDownloader::Downloadable show all
Defined in:
lib/ruby_tapas_downloader/downloadables/episode.rb

Overview

An Ruby Tapas Episode.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, link, files) ⇒ Episode

Returns a new instance of Episode.



15
16
17
18
19
# File 'lib/ruby_tapas_downloader/downloadables/episode.rb', line 15

def initialize(title, link, files)
  @title = title
  @link  = link
  @files = files
end

Instance Attribute Details

#filesSet<RubyTapasDownloader::Downloadables::File> (readonly)

Returns the Set of Files for that episode.

Returns:



13
14
15
# File 'lib/ruby_tapas_downloader/downloadables/episode.rb', line 13

def files
  @files
end

Returns the link to the Episode.

Returns:

  • (String)

    the link to the Episode.



9
10
11
# File 'lib/ruby_tapas_downloader/downloadables/episode.rb', line 9

def link
  @link
end

#titleString (readonly)

Returns the title of the Episode.

Returns:

  • (String)

    the title of the Episode.



6
7
8
# File 'lib/ruby_tapas_downloader/downloadables/episode.rb', line 6

def title
  @title
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/ruby_tapas_downloader/downloadables/episode.rb', line 39

def ==(other)
  title == other.title && link == other.link && files == other.files
end

#download(basepath, agent) ⇒ Object

Download the Episode.



31
32
33
34
35
36
37
# File 'lib/ruby_tapas_downloader/downloadables/episode.rb', line 31

def download(basepath, agent)
  episode_path = File.join basepath, sanitized_title
  RubyTapasDownloader.logger.info 'Starting download of episode ' \
                                  "`#{ title }' in `#{ episode_path }'..."
  FileUtils.mkdir_p episode_path
  files.each { |file| file.download episode_path, agent }
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ruby_tapas_downloader/downloadables/episode.rb', line 43

def eql?(other)
  title.eql?(other.title) && link.eql?(other.link) && files.eql?(other.files)
end

#hashObject



47
48
49
# File 'lib/ruby_tapas_downloader/downloadables/episode.rb', line 47

def hash
  title.hash + link.hash + files.hash
end

#sanitized_titleString

Clean title to be used in path names.

Returns:

  • (String)

    the sanitized title.



24
25
26
# File 'lib/ruby_tapas_downloader/downloadables/episode.rb', line 24

def sanitized_title
  @sanitized_title ||= title.downcase.gsub(/[^\w<>#?!$]+/, '-')
end