class Application

Attributes

output[RW]
password[RW]
type[RW]
url[RW]
user[RW]

Public Instance Methods

run() click to toggle source
# File lib/application.rb, line 9
def run
  # Parsing command line arguments
  OptionParser.new do |opts|
    opts.banner = "Usage: down_universe [options] url output.It Downloads the given 'url' and saves it in 'output' file"

    opts.on("--user", "Sets the HTTP or FTP user.") do |user|
      self.user = user
    end

    opts.on("--password", "Sets the HTTP or FTP password.") do |password|
      self.password = password
    end

    opts.on("-t", "--type DOWNLOAD_TYPE", "Sets the download type available types are 'torrent', 'http' or 'ftp'. 'http' is the default value.") do |type|
      self.type = type
    end
  end.parse!

  # Get the output path and url from the ARGV variable
  self.output = ARGV.pop
  self.url = ARGV.pop

  # Set default download type to http
  self.type = 'http'

  case self.type.downcase
  when 'http'
    http_download(self.url, self.output, self.user, self.password)
  when 'ftp'
    puts "Not implemented yet."
  when 'torrent'
    puts "Not implemented yet."
  else
    puts "The 'type' option could be one of the 'http', 'ftp' or 'torrent' options."
  end
end