Class: Mechanize::FileSaver

Inherits:
Download show all
Defined in:
lib/mechanize/file_saver.rb

Overview

This is a pluggable parser that automatically saves every file it encounters. Unlike Mechanize::DirectorySaver, the file saver saves the responses as a tree, reflecting the host and file path.

Example

This example saves all .pdf files

require 'mechanize'

agent = Mechanize.new
agent.pluggable_parser.pdf = Mechanize::FileSaver
agent.get 'http://example.com/foo.pdf'

Dir['example.com/*'] # => foo.pdf

Constant Summary

Constants included from Parser

Parser::SPECIAL_FILENAMES

Instance Attribute Summary collapse

Attributes inherited from Download

#body_io

Attributes included from Parser

#code, #response, #uri

Instance Method Summary collapse

Methods inherited from Download

#body, #save, #save!

Methods included from Parser

#extract_filename, #fill_header, #find_free_name

Constructor Details

#initialize(uri = nil, response = nil, body_io = nil, code = nil) ⇒ FileSaver

Returns a new instance of FileSaver.


23
24
25
26
27
28
29
# File 'lib/mechanize/file_saver.rb', line 23

def initialize uri = nil, response = nil, body_io = nil, code = nil
  @full_path = true

  super

  save @filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename


21
22
23
# File 'lib/mechanize/file_saver.rb', line 21

def filename
  @filename
end