module Mechanize::Parser

Public Instance Methods

save_to(directory) click to toggle source

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.

@note This method expects a #save! method to be defined by the

class extending +Mechanize::Parser+, e.g. +Mechanize::File#save!+
and +Mechanize::Download#save!+.

@param directory [String] @return [String]

# 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) click to toggle source

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.

@note This method expects a #save! method to be defined by the

class extending +Mechanize::Parser+, e.g. +Mechanize::File#save!+
and +Mechanize::Download#save!+.

@param directory [String] @return [String]

# 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