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. It saves the files 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

#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.



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

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.



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

def filename
  @filename
end