Class: Mechanize::DirectorySaver
- Defined in:
- lib/mechanize/directory_saver.rb
Overview
Constant Summary
Constants included from Parser
Instance Attribute Summary
Attributes inherited from Download
Attributes included from Parser
Class Method Summary collapse
-
.decode_filename? ⇒ Boolean
True if downloaded files should have their names decoded before saving.
-
.directory ⇒ Object
The directory downloaded files will be saved to.
-
.save_to(directory, options = {}) ⇒ Object
Creates a DirectorySaver subclass that will save responses to the given
directory
.
Instance Method Summary collapse
-
#initialize(uri = nil, response = nil, body_io = nil, code = nil) ⇒ DirectorySaver
constructor
Saves the
body_io
into the directory specified for this DirectorySaver by save_to.
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) ⇒ DirectorySaver
Saves the body_io
into the directory specified for this DirectorySaver by save_to. The filename is chosen by Mechanize::Parser#extract_filename.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mechanize/directory_saver.rb', line 48 def initialize uri = nil, response = nil, body_io = nil, code = nil directory = self.class.directory raise Mechanize::Error, 'no save directory specified - ' \ 'use Mechanize::DirectorySaver.save_to ' \ 'and register the resulting class' unless directory super @filename = CGI.unescape(@filename) if self.class.decode_filename? path = File.join directory, @filename save path end |
Class Method Details
.decode_filename? ⇒ Boolean
True if downloaded files should have their names decoded before saving.
40 41 42 |
# File 'lib/mechanize/directory_saver.rb', line 40 def self.decode_filename? @options[:decode_filename] end |
.directory ⇒ Object
The directory downloaded files will be saved to.
33 34 35 |
# File 'lib/mechanize/directory_saver.rb', line 33 def self.directory @directory end |
.save_to(directory, options = {}) ⇒ Object
Creates a DirectorySaver subclass that will save responses to the given directory
. If options
includes a decode_filename
value set to true
then the downloaded filename will be ran through CGI.unescape
before being saved.
21 22 23 24 25 26 27 28 |
# File 'lib/mechanize/directory_saver.rb', line 21 def self.save_to directory, = {} directory = File. directory Class.new self do |klass| klass.instance_variable_set :@directory, directory klass.instance_variable_set :@options, end end |