Module: Mechanize::Parser
- Defined in:
- lib/grubby/mechanize/parser.rb
Instance Method Summary collapse
-
#save_to(directory) ⇒ String
Saves the payload to a specified directory, using the default filename suggested by the server.
-
#save_to!(directory) ⇒ String
Saves the payload to a specified directory, using the default filename suggested by the server.
Instance Method Details
#save_to(directory) ⇒ String
This method expects a #save!
method to be defined by the class extending Mechanize::Parser
, e.g. Mechanize::File#save! and Mechanize::Download#save!.
Saves the payload to a specified directory, using the default filename suggested by the server. If a file with that name already exists, this method will try to find a free filename by appending numbers to the default filename. Returns the full path of the saved file.
17 18 19 20 21 22 23 24 |
# File 'lib/grubby/mechanize/parser.rb', line 17 def save_to(directory) raise "#{self.class}#save! is not defined" unless self.respond_to?(:save!) FileUtils.mkdir_p(directory) path = find_free_name(File.join(directory, @filename)) save!(path) path end |
#save_to!(directory) ⇒ String
This method expects a #save!
method to be defined by the class extending Mechanize::Parser
, e.g. Mechanize::File#save! and Mechanize::Download#save!.
Saves the payload to a specified directory, using the default filename suggested by the server. If a file with that name already exists, that file will be overwritten. Returns the full path of the saved file.
37 38 39 40 41 42 43 44 |
# File 'lib/grubby/mechanize/parser.rb', line 37 def save_to!(directory) raise "#{self.class}#save! is not defined" unless self.respond_to?(:save!) FileUtils.mkdir_p(directory) path = File.join(directory, @filename) save!(path) path end |