Class: Downer::DownloadManager
- Inherits:
-
Object
- Object
- Downer::DownloadManager
- Defined in:
- lib/downer/download_manager.rb
Instance Attribute Summary collapse
-
#downloaded_files ⇒ Object
readonly
Returns the value of attribute downloaded_files.
-
#output ⇒ Object
Returns the value of attribute output.
-
#source_type ⇒ Object
Returns the value of attribute source_type.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#target_directory ⇒ Object
Returns the value of attribute target_directory.
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
Instance Method Summary collapse
-
#check_directory ⇒ Object
Determine whether the direcotry specified exists.
-
#initialize(url_source, target_directory, output, options = {}) ⇒ DownloadManager
constructor
A new instance of DownloadManager.
-
#print_session_summary(worker) ⇒ Object
Tells us what worked and what failed.
- #start ⇒ Object
Constructor Details
#initialize(url_source, target_directory, output, options = {}) ⇒ DownloadManager
Returns a new instance of DownloadManager.
15 16 17 18 19 20 |
# File 'lib/downer/download_manager.rb', line 15 def initialize(url_source, target_directory, output, ={}) @url_source = url_source @output = output @target_directory = append_slash_to_path(target_directory) @strategy = StrategyFinder::find_strategy(@url_source, ) end |
Instance Attribute Details
#downloaded_files ⇒ Object (readonly)
Returns the value of attribute downloaded_files.
13 14 15 |
# File 'lib/downer/download_manager.rb', line 13 def downloaded_files @downloaded_files end |
#output ⇒ Object
Returns the value of attribute output.
12 13 14 |
# File 'lib/downer/download_manager.rb', line 12 def output @output end |
#source_type ⇒ Object
Returns the value of attribute source_type.
12 13 14 |
# File 'lib/downer/download_manager.rb', line 12 def source_type @source_type end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
13 14 15 |
# File 'lib/downer/download_manager.rb', line 13 def strategy @strategy end |
#target_directory ⇒ Object
Returns the value of attribute target_directory.
12 13 14 |
# File 'lib/downer/download_manager.rb', line 12 def target_directory @target_directory end |
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
13 14 15 |
# File 'lib/downer/download_manager.rb', line 13 def urls @urls end |
Instance Method Details
#check_directory ⇒ Object
Determine whether the direcotry specified exists. If it does not, see if its parent is writable. If not, give up and throw error
55 56 57 58 59 60 61 62 |
# File 'lib/downer/download_manager.rb', line 55 def check_directory if File.writable?(@target_directory) return true else #FileUtils.mkdir(@target_directory) raise WriteFailed end end |
#print_session_summary(worker) ⇒ Object
Tells us what worked and what failed
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/downer/download_manager.rb', line 37 def print_session_summary(worker) @output.puts "Session complete." @output.puts "\n\n" @output.puts "----------------------------------" @output.puts "SUMMARY:" @output.puts "Successful downloads: (#{worker.successful_downloads.size})" @output.puts "Failed downloads: (#{worker.failed_downloads.size}): " worker.failed_downloads.each do |fail| @output.puts " * #{fail}" end end |
#start ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/downer/download_manager.rb', line 22 def start check_directory if @strategy && @strategy.source_valid? urls = @strategy.get_urls @output.puts "Starting download on #{urls.size} files" worker = DownloadWorker.new(urls, @target_directory, @output) @downloaded_files = worker.start print_session_summary(worker) else @output.puts "Could not open url source #{@url_source}" end end |