Class: Docsplit::CommandLine
- Inherits:
-
Object
- Object
- Docsplit::CommandLine
- Defined in:
- lib/docsplit/command_line.rb
Overview
A single command-line utility to separate a PDF into all its component parts.
Constant Summary collapse
- BANNER =
"docsplit breaks apart documents into images, text, or individual pages.\nIt wraps GraphicsMagick, Poppler, PDFTK, and JODConverter.\n\nUsage:\n docsplit COMMAND [OPTIONS] path/to/doc.pdf\n Main commands:\npages, images, text, pdf.\n Metadata commands:\nauthor, date, creator, keywords, producer, subject, title, length.\n\nExample:\n docsplit images --size 700x --format jpg document.pdf\n\nDependencies:\n Ruby, Java, A working GraphicsMagick (gm) command,\n and a headless OpenOffice server for non-PDF documents.\n\nOptions:\n(size, pages and format can take comma-separated values)\n\n"
Instance Method Summary collapse
-
#initialize ⇒ CommandLine
constructor
Creating a CommandLine runs off of the contents of ARGV.
-
#run ⇒ Object
Delegate to the Docsplit Ruby API to perform all extractions.
-
#usage ⇒ Object
Print out the usage help message.
Constructor Details
#initialize ⇒ CommandLine
Creating a CommandLine runs off of the contents of ARGV.
33 34 35 36 37 38 |
# File 'lib/docsplit/command_line.rb', line 33 def initialize cmd = ARGV.shift @command = cmd && cmd.to_sym run end |
Instance Method Details
#run ⇒ Object
Delegate to the Docsplit Ruby API to perform all extractions.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/docsplit/command_line.rb', line 41 def run begin case @command when :images then Docsplit.extract_images(ARGV, ) when :pages then Docsplit.extract_pages(ARGV, ) when :text then Docsplit.extract_text(ARGV, ) when :pdf then Docsplit.extract_pdf(ARGV, ) else if METADATA_KEYS.include?(@command) value = Docsplit.send("extract_#{@command}", ARGV, ) puts value unless value.nil? else usage end end rescue ExtractionFailed => e puts e..chomp exit(1) end end |
#usage ⇒ Object
Print out the usage help message.
63 64 65 66 |
# File 'lib/docsplit/command_line.rb', line 63 def usage puts "\n#{@option_parser}\n" exit end |