class Downcer::CLI
Public Class Methods
new(url)
click to toggle source
# File lib/downcer/cli.rb, line 12 def initialize(url) @url = URI.parse(URI.encode(url)) @config = get_config(@url) rescue NoMethodError, URI::InvalidURIError => e abort 'Usage: downcer <url>' rescue SystemCallError => e abort e.to_s end
start(*args)
click to toggle source
# File lib/downcer/cli.rb, line 8 def self.start(*args) self.new(args.first).download end
Public Instance Methods
download()
click to toggle source
# File lib/downcer/cli.rb, line 21 def download puts "Use `#{@config['command']}`" puts '--' exec "#{@config['command']} #{@config['option']} '#{@url}'" end
Private Instance Methods
get_config(url)
click to toggle source
# File lib/downcer/cli.rb, line 28 def get_config(url) domain = url.host yaml = YAML.load_file(CONFIG) config = yaml.select { |host, v| domain.match(/#{host}/) }.values.first config || yaml['default'] || { 'command' => 'curl', 'option' => '-LO' } rescue Exception => e abort e.to_s end