From 1ea5d78f268bece1396c0bfd65ce34cf1638eb7e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 12 Jun 2012 22:02:40 -0400 Subject: [PATCH] Use strings instead of symbols for the downloader type. --- bin/whatever-dl | 10 +++++++--- lib/whatever-dl/configuration.rb | 4 ++-- lib/whatever-dl/downloader.rb | 4 ++-- lib/whatever-dl/website.rb | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/bin/whatever-dl b/bin/whatever-dl index b9ea02c..b3ed1ca 100755 --- a/bin/whatever-dl +++ b/bin/whatever-dl @@ -59,8 +59,8 @@ opts.each do |opt, arg| end # Warn about nonsensical options. -if options[:continue] and not Configuration::DOWNLOAD_METHOD == :wget - log.warn('The --continue flag does nothing unless DOWNLOAD_METHOD is :wget.') +if options[:continue] and not cfg.download_method == 'wget' + log.warn("The --continue flag does nothing unless download_method is wget.") end # Note that GetoptLong steals its arguments from ARGV, so we don't need @@ -73,6 +73,9 @@ if (ARGV.length < 1) then Kernel.exit(ExitCodes::EXIT_NO_URL) end + +cfg = Configuration.new() + # Factory method. site = Website.create(ARGV[0]) @@ -92,7 +95,8 @@ end # The Downloader class is a factory; it should decide # which subclass we get. -downloader = Downloader.create(Configuration::DOWNLOAD_METHOD) +puts "download_method: #{cfg.download_method}" +downloader = Downloader.create(cfg.download_method) # Attempt to download the file, and rescue and report # any (predictable) exceptions. The wget downloader will diff --git a/lib/whatever-dl/configuration.rb b/lib/whatever-dl/configuration.rb index 595d21f..9cca34a 100644 --- a/lib/whatever-dl/configuration.rb +++ b/lib/whatever-dl/configuration.rb @@ -3,9 +3,9 @@ require 'yaml' class Configuration # Configurable Options # - # We support a couple of different download methods. The :openuri + # We support a couple of different download methods. The 'openuri' # method utilizes the ruby open-uri library, and provides its own - # progress bar with no external dependencies. The :wget method, on the + # progress bar with no external dependencies. The 'wget' method, on the # other hand, requires GNU Wget (http://www.gnu.org/software/wget/), # but will support auto-resume of partially-downloaded files for # example. diff --git a/lib/whatever-dl/downloader.rb b/lib/whatever-dl/downloader.rb index 85cc4e3..c62ebf9 100644 --- a/lib/whatever-dl/downloader.rb +++ b/lib/whatever-dl/downloader.rb @@ -21,9 +21,9 @@ class Downloader def self.create(download_method) # Return the subclass corresponding to download_method. case download_method - when :openuri + when 'openuri' return OpenUriDownloader.new() - when :wget + when 'wget' return WgetDownloader.new() end end diff --git a/lib/whatever-dl/website.rb b/lib/whatever-dl/website.rb index e9e65ca..1c87be6 100644 --- a/lib/whatever-dl/website.rb +++ b/lib/whatever-dl/website.rb @@ -82,7 +82,8 @@ class Website def initialize(url) @url = url - self.headers = { 'User-Agent' => Configuration::USER_AGENT } + cfg = Configuration.new() + self.headers = { 'User-Agent' => cfg.user_agent } end -- 2.44.2