This is the base class for the Pluggable Parsers. If Mechanize cannot find an appropriate class to use for the content type, this class will be used. For example, if you download an image/jpeg, Mechanize will not know how to parse it, so this class will be instantiated.
This is a good class to use as the base class for building your own pluggable parsers.
require 'mechanize' agent = Mechanize.new agent.get('http://example.com/foo.jpg').class #=> Mechanize::File
Creates a new file retrieved from the given uri and response object. The body is the HTTP response body and code is the HTTP status.
# File lib/mechanize/file.rb, line 38 def initialize uri = nil, response = nil, body = nil, code = nil @uri = uri @body = body @code = code @full_path = false unless defined? @full_path fill_header response extract_filename yield self if block_given? end
Use this method to save the content of this object to filename.
file.save 'index.html' file.save 'index.html' # saves index.html.1 file.save 'index.html'
# File lib/mechanize/file.rb, line 58 def save filename = nil filename = find_free_name filename save! filename end
Use this method to save the content of this object to filename. This method will overwrite any existing filename that exists with the same name.
file.save 'index.html' file.save! 'index.html' # overwrite original file
# File lib/mechanize/file.rb, line 73 def save! filename = nil dirname = File.dirname filename FileUtils.mkdir_p dirname open filename, 'wb' do |f| f.write body end end
Generated with the Darkfish Rdoc Generator 2.