Class: Pdfrb::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/configuration.rb

Overview

Per-Document configuration. A frozen Hash-with-defaults that can be deep-merged with user overrides. Mirrors HexaPDF::Configuration in shape, but starts minimal — settings get added as features land.

Constant Summary collapse

DEFAULTS =
{
  # When true, malformed PDFs are recovered heuristically instead
  # of raising MalformedPdfError. Production readers should keep
  # this true; strict validators can flip it off.
  "source.recover_malformed" => true,

  # When true, an encrypted PDF is decrypted on open (using
  # decryption_opts passed to Document.new). Disable for raw
  # inspection of ciphertext.
  "document.auto_decrypt" => true,

  # Callback invoked when a string field has an invalid encoding.
  # Default: replace with U+FFFD in UTF-8.
  "document.on_invalid_string" => ->(str) { str.encode("UTF-8", invalid: :replace, undef: :replace) },

  # When true, errors that Pdfrb can auto-correct are raised after
  # all (so test runs catch corruption). Production readers flip
  # this off.
  "parser.on_correctable_error" => ->(_doc, _msg) { false },

  # When true, Stream objects larger than writer.compress_min_size
  # are emitted with /Filter /FlateDecode on write. Existing
  # /Filter values are honoured (no double compression).
  "writer.compress_streams" => false,
  "writer.compress_min_size" => 256
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(overrides = {}) ⇒ Configuration

Returns a new instance of Configuration.



37
38
39
40
# File 'lib/pdfrb/configuration.rb', line 37

def initialize(overrides = {})
  @settings = deep_merge(DEFAULTS.dup, overrides)
  freeze
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



35
36
37
# File 'lib/pdfrb/configuration.rb', line 35

def settings
  @settings
end

Instance Method Details

#[](key) ⇒ Object



42
43
44
# File 'lib/pdfrb/configuration.rb', line 42

def [](key)
  @settings[key]
end

#[]=(key, value) ⇒ Object



46
47
48
# File 'lib/pdfrb/configuration.rb', line 46

def []=(key, value)
  @settings[key] = value
end