Parent

Methods

Included Modules

Mechanize::File

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.

Example

  require 'mechanize'

  agent = Mechanize.new
  agent.get('http://example.com/foo.jpg').class  #=> Mechanize::File

Attributes

body[RW]

The HTTP response body, the raw file contents

filename[RW]

The filename for this file based on the content-disposition of the response or the basename of the URL

Public Class Methods

new(uri = nil, response = nil, body = nil, code = nil) click to toggle source

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
38:   def initialize uri = nil, response = nil, body = nil, code = nil
39:     @uri  = uri
40:     @body = body
41:     @code = code
42: 
43:     @full_path = false unless defined? @full_path
44: 
45:     fill_header response
46:     extract_filename
47: 
48:     yield self if block_given?
49:   end

Public Instance Methods

save(filename = nil) click to toggle source

Use this method to save the content of this object to filename

    # File lib/mechanize/file.rb, line 54
54:   def save filename = nil
55:     filename = find_free_name filename
56: 
57:     open filename, 'wb' do |f|
58:       f.write body
59:     end
60:   end
Also aliased as: save_as
save_as(filename = nil) click to toggle source
Alias for: save

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.