Class: Preflight::Rules::BoxPresence

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

Overview

Specify the presence of page boxes

Arguments: hash containing :any or :all key with an array value of box names as symbols

Usage:

class MyPreflight
  include Preflight::Profile

  rule Preflight::Rules::BoxPresence, :any => [:MediaBox, :CropBox]
  rule Preflight::Rules::BoxPresence, :all => [:MediaBox, :CropBox]
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BoxPresence

Returns a new instance of BoxPresence.



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

def initialize(options)
  if options[:any].nil? && options[:all].nil?
    raise "Preflight::Rules::BoxPresence requires :any or :all option"
  elsif options[:any] && options[:all]
    raise "Preflight::Rules::BoxPresence requires only one of :any or :all option"
  end

  @options = options
end

Instance Attribute Details

#issuesObject (readonly)

Returns the value of attribute issues.



22
23
24
# File 'lib/preflight/rules/box_presence.rb', line 22

def issues
  @issues
end

Instance Method Details

#page=(page) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/preflight/rules/box_presence.rb', line 34

def page=(page)
  dict = page.attributes

  present_boxes = dict.keys & [:MediaBox, :CropBox, :TrimBox, :ArtBox]

  if @options[:any] && !@options[:any].any? { |b| present_boxes.include?(b) }
    @issues = [Issue.new("page must have any of #{@options[:any].join(", ")}", self, :page => page.number)]
  elsif @options[:all] && !@options[:all].all? { |b| present_boxes.include?(b) }
    @issues = [Issue.new("page must have all of #{@options[:all].join(", ")}", self, :page => page.number)]
  else
    @issues = []
  end
end