I browsed the documentation Mechanize. The below is for .pdf
only.
require 'mechanize'
agent = Mechanize.new
agent.pluggable_parser.pdf = Mechanize::FileSaver
agent.get 'http://example.com/foo.pdf'
The type of file doesn't matter; any file accessible over the net can be obtained via mechanize, which is a tool for automating interaction with Mechanize.
The file will be stored in the directory where the program was run. Use Mechanize::Download instead of Mechanize::FileSaver
to specify where the file should be downloaded to. Example code here: https://stackoverflow.com/a/9105153/429758 (Specify the full path in the filename)
Mechanize doesn't use a browser while downloading. For all intents and purposes, Mechanize acts like a web browser with no user interface
via http://ruby.about.com/od/tasks/a/The-Mechanize-2-0-Handbook.htm
Do checkout the EXAMPLES page on mechanize documentation for further examples about how to use mechanize.