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

Version Path
scrapers-3.2.0 lib/scrapers/download.rb
scrapers-3.1.0 lib/scrapers/download.rb
scrapers-3.0.0 lib/scrapers/download.rb
scrapers-2.1.0 lib/scrapers/download.rb
scrapers-2.0.2 lib/scrapers/download.rb
scrapers-2.0.1 lib/scrapers/download.rb
scrapers-2.0.0 lib/scrapers/download.rb
scrapers-1.5.6 lib/scrapers/download.rb
scrapers-1.5.5 lib/scrapers/download.rb
scrapers-1.5.4 lib/scrapers/download.rb
scrapers-1.5.3 lib/scrapers/download.rb
scrapers-1.5.2 lib/scrapers/download.rb
scrapers-1.5.1 lib/scrapers/download.rb
scrapers-1.5.0 lib/scrapers/download.rb
scrapers-1.4.0 lib/scrapers/download.rb
scrapers-1.3.0 lib/scrapers/download.rb
scrapers-1.2.0 lib/scrapers/download.rb
scrapers-1.1.0 lib/scrapers/download.rb
scrapers-1.0.0 lib/scrapers/download.rb