Class: Mechanize::FileSaver
- 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
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Attributes inherited from Download
Attributes included from Parser
Instance Method Summary collapse
-
#initialize(uri = nil, response = nil, body_io = nil, code = nil) ⇒ FileSaver
constructor
A new instance of FileSaver.
Methods inherited from Download
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
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
21 22 23 |
# File 'lib/mechanize/file_saver.rb', line 21 def filename @filename end |