Class: Preflight::Rules::MatchInfoEntries

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

Overview

Every PDF has an optional ‘Info’ dictionary. Check that the target file has certain keys and that the keys match a given regexp

Arguments: the required keys

Usage:

class MyPreflight
  include Preflight::Profile

  rule Preflight::Rules::MatchInfoEntries, {:GTS_PDFXVersion => /\APDF\/X/}
end

Instance Method Summary collapse

Constructor Details

#initialize(matches = {}) ⇒ MatchInfoEntries

Returns a new instance of MatchInfoEntries.



20
21
22
# File 'lib/preflight/rules/match_info_entries.rb', line 20

def initialize(matches = {})
  @matches = matches
end

Instance Method Details

#check_hash(ohash) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/preflight/rules/match_info_entries.rb', line 24

def check_hash(ohash)
  array = []
  info = ohash.object(ohash.trailer[:Info])
  @matches.each do |key, regexp|
    if !info.has_key?(key)
      array << Issue.new("Info dict missing required key", self, :key => key)
    elsif !info[key].to_s.match(regexp)
      array << Issue.new("value of Info entry #{key} doesn't match #{regexp}", self, :key    => key,
                                                                                     :regexp => regexp)
    end
  end
  array
end