Class: Downlow::Http
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Fetcher
#destination, #local_path, #options, #tmp_dir, #url
Instance Method Summary collapse
Methods inherited from Fetcher
fetch, #fetched?, fetcher_for, handles, #initialize
Constructor Details
This class inherits a constructor from Downlow::Fetcher
Instance Method Details
#fetch ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/downlow/fetchers/http.rb', line 8 def fetch data = "" filename = destination.basename open(url.to_s) do |u| if disposition = u.['content-disposition'] and disposition.match(/filename=\"([^\"]+)\"/) filename = $1 else filename = Pathname.new(u.base_uri.to_s).basename end data << u.read end filename = filename.to_s.gsub(/\?(.*)$/,'') self.destination = destination.dirname + filename File.open(destination, 'w') {|f| f << data } @local_path = destination end |