Class: RubyTapasDownloader::Downloadables::File

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

Overview

The File resource of an Episode.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, link) ⇒ File

Returns a new instance of File.



11
12
13
14
# File 'lib/ruby_tapas_downloader/downloadables/file.rb', line 11

def initialize(name, link)
  @name = name
  @link = link
end

Instance Attribute Details

Returns the link to download the File.

Returns:

  • (String)

    the link to download the File.



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

def link
  @link
end

#nameString (readonly)

Returns the name of the File.

Returns:

  • (String)

    the name of the File.



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

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
# File 'lib/ruby_tapas_downloader/downloadables/file.rb', line 28

def ==(other)
  name == other.name && link == other.link
end

#download(basepath, agent) ⇒ Object

Download the File.



19
20
21
22
23
24
25
26
# File 'lib/ruby_tapas_downloader/downloadables/file.rb', line 19

def download(basepath, agent)
  FileUtils.mkdir_p basepath

  file_path = File.join(basepath, name)
  RubyTapasDownloader.logger.info "Starting download of file `#{ name }' " \
                                  "in `#{ file_path }'..."
  agent.download link, file_path unless File.exist? file_path
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/ruby_tapas_downloader/downloadables/file.rb', line 32

def eql?(other)
  name.eql?(other.name) && link.eql?(other.link)
end

#hashObject



36
37
38
# File 'lib/ruby_tapas_downloader/downloadables/file.rb', line 36

def hash
  name.hash + link.hash
end