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 =
<<-EOS.freeze docsplit breaks apart documents into images, text, or individual pages. It wraps GraphicsMagick, Poppler, PDFTK, and JODConverter. Usage: docsplit COMMAND [OPTIONS] path/to/doc.pdf Main commands: pages, images, text, pdf. Metadata commands: author, date, creator, keywords, producer, subject, title, length. Example: docsplit images --size 700x --format jpg document.pdf Dependencies: Ruby, Java, A working GraphicsMagick (gm) command, and a headless OpenOffice server for non-PDF documents. Options: (size, pages and format can take comma-separated values) EOS
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.
31 32 33 34 35 36 |
# File 'lib/docsplit/command_line.rb', line 31 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.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/docsplit/command_line.rb', line 39 def run case @command when :images then Docsplit.extract_images(ARGV, @options) when :pages then Docsplit.extract_pages(ARGV, @options) when :text then Docsplit.extract_text(ARGV, @options) when :pdf then Docsplit.extract_pdf(ARGV, @options) else if METADATA_KEYS.include?(@command) value = Docsplit.send("extract_#{@command}", ARGV, @options) puts value unless value.nil? else usage end end rescue ExtractionFailed => e puts e..chomp exit(1) end |
#usage ⇒ Object
Print out the usage help message.
59 60 61 62 |
# File 'lib/docsplit/command_line.rb', line 59 def usage puts "\n#{@option_parser}\n" exit end |