Class: GS::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/gs-ruby/configuration.rb

Overview

A configuration object used to define the path to the Ghostscript command, any default options and the logger that should be used.

  • This is usually not instantiated directly, but rather by way of calling GS.configure.

Instance Attribute Summary collapse

Instance Attribute Details

#bin_pathString

Gets the bin path to the Ghostscript command.

  • If no path has been set, it returns 'gs' as the default.


20
21
22
# File 'lib/gs-ruby/configuration.rb', line 20

def bin_path
  @bin_path ||= 'gs'
end

#default_optionsHash

Gets the default options.

  • If no default options have been set, it returns a set of options where GS::BATCH is set by default.

Examples:

Configuring a default option that requires a value

GS.configure do |config|
  # Results in the switch -sProcessColorModel=DeviceCMYK
  config.default_options[GS::PROCESS_COLOR_MODEL] = 'DeviceCMYK'
end

Configuring a default option that does not require a value

GS.configure do |config|
  # Results in the switch -dNOPAUSE
  config.default_options[GS::NO_PAUSE] = nil
end

Removing a default option that already exists

GS.configure do |config|
  # Currently, GS::BATCH is the only option configured by default.
  # Not sure why you might want to remove it, but if you do, simply
  # delete it from the options Hash - same goes for any other option.
  config.default_options.delete(GS::BATCH)
end

See Also:


52
53
54
# File 'lib/gs-ruby/configuration.rb', line 52

def default_options
  @default_options ||= { GS::BATCH => nil }
end

#loggerLogger

Gets the logger object.

  • If no logger has been set, it instantiates and returns a new logger configured to log to $stdout.


62
63
64
65
66
# File 'lib/gs-ruby/configuration.rb', line 62

def logger
  @logger ||= Logger.new($stdout).tap do |logger|
    logger.progname = bin_path
  end
end