Class: TnPDF::PageSection

Inherits:
Object
  • Object
show all
Defined in:
lib/tn_pdf/box.rb,
lib/tn_pdf/page_section.rb

Defined Under Namespace

Classes: Box

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bottomObject



38
39
40
# File 'lib/tn_pdf/page_section.rb', line 38

def bottom
  @bottom ||= 0
end

#centerObject

Returns the value of attribute center.



3
4
5
# File 'lib/tn_pdf/page_section.rb', line 3

def center
  @center
end

#center_boxObject (readonly)

Returns the value of attribute center_box.



4
5
6
# File 'lib/tn_pdf/page_section.rb', line 4

def center_box
  @center_box
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/tn_pdf/page_section.rb', line 6

def height
  @height
end

#leftObject

Returns the value of attribute left.



3
4
5
# File 'lib/tn_pdf/page_section.rb', line 3

def left
  @left
end

#left_boxObject (readonly)

Returns the value of attribute left_box.



4
5
6
# File 'lib/tn_pdf/page_section.rb', line 4

def left_box
  @left_box
end

#rightObject

Returns the value of attribute right.



3
4
5
# File 'lib/tn_pdf/page_section.rb', line 3

def right
  @right
end

#right_boxObject (readonly)

Returns the value of attribute right_box.



4
5
6
# File 'lib/tn_pdf/page_section.rb', line 4

def right_box
  @right_box
end

#topObject



34
35
36
# File 'lib/tn_pdf/page_section.rb', line 34

def top
  @top ||= 0
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/tn_pdf/page_section.rb', line 6

def width
  @width
end

Instance Method Details

#boxesObject



30
31
32
# File 'lib/tn_pdf/page_section.rb', line 30

def boxes
  [left_box, center_box, right_box]
end

#render(document, position) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/tn_pdf/page_section.rb', line 42

def render(document, position)
  width ||= document.bounds.width

  box_width = width/(boxes.compact.count)

  boxes.each do |box|
    box.width ||= box_width
  end

  boxes_with_positions = [
    boxes,
    [position[0], (width-boxes[1].width)/2, width-boxes[2].width],
    [position[1]-top]*3
  ].transpose

  boxes_with_positions.each do |box, x_pos, y_pos|
    box.render(document, [x_pos, y_pos], height )
  end
end

#total_heightObject



26
27
28
# File 'lib/tn_pdf/page_section.rb', line 26

def total_height
  height + top + bottom
end