Class: Preflight::Rules::InfoHasKeys

Inherits:
Object
  • Object
show all
Defined in:
lib/preflight/rules/info_has_keys.rb

Overview

Every PDF has an optional ‘Info’ dictionary. Check that the target file has certain keys

Arguments: the required keys

Usage:

class MyPreflight
  include Preflight::Profile

  rule Preflight::Rules::InfoHasKeys, :Title, :CreationDate, :ModDate
end

Instance Method Summary collapse

Constructor Details

#initialize(*keys) ⇒ InfoHasKeys

Returns a new instance of InfoHasKeys.



21
22
23
# File 'lib/preflight/rules/info_has_keys.rb', line 21

def initialize(*keys)
  @keys = keys.flatten
end

Instance Method Details

#check_hash(ohash) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/preflight/rules/info_has_keys.rb', line 25

def check_hash(ohash)
  info = ohash.object(ohash.trailer[:Info])
  missing = @keys - info.keys
  missing.map { |key|
    Issue.new("Info dict missing required key", self, :key => key)
  }
end