Class: Preflight::Rules::ConsistentBoxes

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

Overview

Every page should have identical page boxes

Arguments: none

Usage:

class MyPreflight
  include Preflight::Profile

  rule Preflight::Rules::BoxNesting
end

Constant Summary collapse

DEFAULT_TOLERANCE =

Default tolerance is that each page box MUST be within .03 PDF points of the same box on all other pages

(BigDecimal.new("-0.03")..BigDecimal.new("0.03"))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tolerance = DEFAULT_TOLERANCE) ⇒ ConsistentBoxes

Returns a new instance of ConsistentBoxes.



26
27
28
29
# File 'lib/preflight/rules/consistent_boxes.rb', line 26

def initialize(tolerance = DEFAULT_TOLERANCE)
  @boxes = {}
  @tolerance = tolerance
end

Instance Attribute Details

#issuesObject (readonly)

Returns the value of attribute issues.



24
25
26
# File 'lib/preflight/rules/consistent_boxes.rb', line 24

def issues
  @issues
end

Instance Method Details

#page=(page) ⇒ Object



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

def page=(page)
  @issues = []
  dict = page.attributes

  @boxes[:MediaBox] ||= dict[:MediaBox]
  @boxes[:CropBox]  ||= dict[:CropBox]
  @boxes[:BleedBox] ||= dict[:BleedBox]
  @boxes[:TrimBox]  ||= dict[:TrimBox]
  @boxes[:ArtBox]   ||= dict[:ArtBox]

  %w(MediaBox CropBox BleedBox TrimBox ArtBox).map(&:to_sym).each do |box_type|
    unless subtract_all(@boxes[box_type], dict[box_type]).all? { |diff| @tolerance.include?(diff) }
      @issues << Issue.new("#{box_type} must be consistent across every page", self, :page             => page.number,
                                                                                     :inconsistent_box => box_type)
    end
  end
end