Class: Preflight::Rules::BoxNesting

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

Overview

For each page MediaBox must be the biggest box, followed by the BleedBox or ArtBox, followed by the TrimBox.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBoxNesting

Returns a new instance of BoxNesting.



12
13
14
15
16
# File 'lib/preflight/rules/box_nesting.rb', line 12

def initialize
  @messages = []
  @page_num = 0
  @parent   = {}
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



10
11
12
# File 'lib/preflight/rules/box_nesting.rb', line 10

def messages
  @messages
end

Instance Method Details

#begin_page(hash = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/preflight/rules/box_nesting.rb', line 22

def begin_page(hash = {})
  @page_num += 1
  hash = @parent.merge(hash)

  media  = hash[:MediaBox]
  bleed  = hash[:BleedBox]
  trim   = hash[:TrimBox]
  art    = hash[:ArtBox]

  if media && bleed && (bleed[2] > media[2] || bleed[3] > media[3])
    @messages << "BleedBox must be smaller than MediaBox (page #{@page_num})"
  elsif trim && bleed && (trim[2] > bleed[2] || trim[3] > bleed[3])
    @messages << "TrimBox must be smaller than BleedBox (page #{@page_num})"
  elsif art && bleed && (art[2] > bleed[2] || art[3] > bleed[3])
    @messages << "ArtBox must be smaller than BleedBox (page #{@page_num})"
  elsif trim && media && (trim[2] > media[2] || trim[3] > media[3])
    @messages << "TrimBox must be smaller than MediaBox (page #{@page_num})"
  elsif art && media && (art[2] > media[2] || art[3] > media[3])
    @messages << "ArtBox must be smaller than MediaBox (page #{@page_num})"
  end
end

#begin_page_container(hash = {}) ⇒ Object



18
19
20
# File 'lib/preflight/rules/box_nesting.rb', line 18

def begin_page_container(hash = {})
  @parent.merge!(hash)
end