Sha256: 2676391851ec9471e0a8fd6a2a28f2d73d91716bf0319767105c01675c819114
Contents?: true
Size: 841 Bytes
Versions: 19
Compression:
Stored size: 841 Bytes
Contents
=begin rdoc = DOWNLOAD.RB *Author*:: Tamara Temple <tamara@tamaratemple.com> *Since*:: 2013-05-27 *Copyright*:: (c) 2013 Tamara Temple Web Development *License*:: MIT =end require 'mechanize' module Scrapers module Download def self.download(url,dir=".",overwrite=false) # need a new agent each time! agent = Mechanize.new agent.pluggable_parser.default = Mechanize::Download @dir = validate_directory(dir) dl = agent.get(url) Dir.chdir(@dir) do |dir| if overwrite dl.save!(dl.filename) else dl.save() end end File.join(@dir,dl.filename) end def self.validate_directory(d) raise "#{d} is not a writable directory!" unless File.directory?(d) and File.writable?(d) d end end end
Version data entries
19 entries across 19 versions & 1 rubygems