Class: Simon::Application
- Inherits:
-
Object
- Object
- Simon::Application
- Defined in:
- lib/simon/application.rb
Instance Method Summary collapse
-
#download_torrent ⇒ Object
Downloads the torrent file and saves it in /tmp for passing to transmission.
-
#initialize(options = {}) ⇒ Application
constructor
Creates a new instance of the application complete and initializes its components.
-
#run ⇒ Object
Do real work here.
Constructor Details
#initialize(options = {}) ⇒ Application
Creates a new instance of the application complete and initializes its components
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simon/application.rb', line 17 def initialize(={}) @options = @client = Transmission.new if @options[:download_limit] != 0 @client.download_limit = @options[:download_limit] end if @options[:upload_limit] != 0 @client.upload_limit = @options[:upload_limit] end @progress_bar = ProgressBar.new("Downloading", 1.0) end |
Instance Method Details
#download_torrent ⇒ Object
Downloads the torrent file and saves it in /tmp for passing to transmission
52 53 54 55 56 57 58 59 60 |
# File 'lib/simon/application.rb', line 52 def download_torrent orig = open(@options[:file]) tmp = Tempfile.new('simon-torrent') tmp.write(orig.read) # We need to reopen the file to get the torrent data tmp.open @torrent_file = tmp @torrent_path = tmp.path end |
#run ⇒ Object
Do real work here
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/simon/application.rb', line 30 def run # Fetch the torrent, stuff it into a temporary file download_torrent # Setup the torrent session torrent = @client.open(@torrent_path) torrent.download_to(File.(@options[:target])) # Start the download and wait torrent.start puts "Starting download" if @options[:no_progress] until torrent.just_finished? sleep 0.5 end else until torrent.just_finished? @progress_bar.set(torrent.stat.progress) sleep 0.5 end end end |