Sha256: a3c94925e596233d663583e73aed2e1e24789d8b2073a923b862990979bd01a2

Contents?: true

Size: 784 Bytes

Versions: 1

Compression:

Stored size: 784 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)
      Scrapers.agent.pluggable_parser.default = Mechanize::Download
      @dir = validate_directory(dir)
      dl = Scrapers.agent.get(url)
      Dir.chdir(@dir) do |dir|
        if overwrite
          dl.save!()
        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

1 entries across 1 versions & 1 rubygems

Version Path
scrapers-0.4.3 lib/scrapers/download.rb