Class: BitTorrent

Inherits:
Object
  • Object
show all
Defined in:
lib/bit_torrent.rb

Defined Under Namespace

Classes: DownloadError

Constant Summary collapse

DEFAULTS =
{
  :upload_rate_limit => 0,
  :seed_ratio => 1.5,
  :seed_time => 1440, # minutes
  :connect_timeout => 60,
  :timeout => 60,
  :stop_timeout => 0,
  :use_tor_proxy => false,
  :destination_directory => "."
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ BitTorrent

Returns a new instance of BitTorrent.



20
21
22
23
24
25
# File 'lib/bit_torrent.rb', line 20

def initialize(source, options = {})
  @sources = [ source ].flatten
  DEFAULTS.keys.each do |option|
    self.instance_variable_set("@#{option}", (options[option] || DEFAULTS[option]))
  end
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources.



17
18
19
# File 'lib/bit_torrent.rb', line 17

def sources
  @sources
end

Class Method Details

.download(sources, options = {}) ⇒ Object



27
28
29
# File 'lib/bit_torrent.rb', line 27

def self.download(sources, options = {})
  new(sources, options).download
end

.download!(sources, options = {}) ⇒ Object



31
32
33
# File 'lib/bit_torrent.rb', line 31

def self.download!(sources, options = {})
  new(sources, options).download!
end

Instance Method Details

#downloadObject



35
36
37
# File 'lib/bit_torrent.rb', line 35

def download
  system(download_commmand)
end

#download!Object



39
40
41
# File 'lib/bit_torrent.rb', line 39

def download!
  download or raise DownloadError
end