Module: GS

Includes:
Options
Defined in:
lib/gs-ruby.rb,
lib/gs-ruby/command.rb,
lib/gs-ruby/options.rb,
lib/gs-ruby/version.rb,
lib/gs-ruby/configuration.rb

Overview

GS Ruby is a simple wrapper for the Ghostscript command - it's assumed that you have the gs command already installed.

Usage

Typical usage might look like:

GS.run('input.ps', GS::OUTPUT_FILE => 'output.pdf')

Or using a block to work with the command before it's run:

GS.run('input.ps') do |command|
  command.option(GS::OUTPUT_FILE, 'output.pdf')
end

Configuration

Global configuration is possible:

GS.configure do |config|
  config.bin_path = '/path/to/gs'
end

Logging

By default all output is logged to $stdout, but the logger can be configured:

# For a single command instance.
GS.run('input.ps') do |command|
  command.logger = # ...
end

# For all command instances.
GS.configure do |config|
  config.logger = # ...
end

See Also:

Defined Under Namespace

Modules: Options Classes: Command, Configuration

Constant Summary collapse

VERSION =
'0.1.0'

Constants included from Options

Options::BATCH, Options::DEVICE, Options::NO_PAUSE, Options::OUTPUT_FILE, Options::PDFA, Options::PDFA_COMPATIBILITY_POLICY, Options::PROCESS_COLOR_MODEL

Class Method Summary collapse

Class Method Details

.configurationConfiguration

Gets the configuration object.

If none was set, a new configuration object is instantiated and returned.

Returns:



57
58
59
# File 'lib/gs-ruby.rb', line 57

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Allows for configuring the library using a block.

Examples:

Configuration using a block

GS.configure do |config|
  # ...
end

Yields:



67
68
69
# File 'lib/gs-ruby.rb', line 67

def configure
  yield(configuration) if block_given?
end

.run(input, options = {}) {|command| ... } ⇒ Process::Status

Instantiates a new command object with any provided options and runs it with the provided input.

Examples:

Run a new command with options

GS.run('input.ps', GS::OUTPUT_FILE => 'output.pdf')

Configure and run a new command

GS.run('path/to/input/file.ps') do |command|
  command.option(GS::OUTPUT_FILE, 'output.pdf')
end

Yields:

  • (command)

Returns:

  • (Process::Status)

    describing the result of running the command

See Also:



86
87
88
89
90
# File 'lib/gs-ruby.rb', line 86

def run(input, options = {})
  command = Command.new(options: options)
  yield(command) if block_given?
  command.run(input)
end