Class: Prune::Parsers::TrParser

Inherits:
Base
  • Object
show all
Defined in:
lib/prune/parsers/document/page/table/tr_parser.rb

Overview

Parser for directive “tr”.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Prune::PObjects

pa, pd, ph, pl, pn, ps

Methods included from Functions

#mm_to_pt, #pt_to_mm

Constructor Details

#initialize(table, options = {}) ⇒ TrParser

Initialize.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/prune/parsers/document/page/table/tr_parser.rb', line 13

def initialize(table, options = {})
  @table = table
  @options = options
  # Boundary of this object.
  @x = @table.page.x
  @y = @table.page.y
  @width = 0.0
  @height = 0.0
  @widths = options[:widths] || @table.options[:widths] || []

  # All td tags inside this tag.
  @tds = []
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



10
11
12
# File 'lib/prune/parsers/document/page/table/tr_parser.rb', line 10

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



9
10
11
# File 'lib/prune/parsers/document/page/table/tr_parser.rb', line 9

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



7
8
9
# File 'lib/prune/parsers/document/page/table/tr_parser.rb', line 7

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



8
9
10
# File 'lib/prune/parsers/document/page/table/tr_parser.rb', line 8

def y
  @y
end

Instance Method Details

#renderObject

Render td tags.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/prune/parsers/document/page/table/tr_parser.rb', line 28

def render
  prev_td = nil
  orig_x = @table.page.x
  orig_y = @table.page.y

  # Get width of the table line.
  @width = @tds.inject(0.0){|result, td| result += td.width}
  # Get the highest column height and set it to all columns.
  @height = @tds.sort_by{|td| td.height}[-1].height

  # Render each td tags.
  @tds.each_with_index do |td, index|
    # Set td height to highest.
    td.height = @height
    # Set x of the page.
    unless prev_td.nil?
      td.x = prev_td.x + prev_td.width
      @table.page.x = td.x
    end
    prev_td = td
    td.render
  end

  # Set x,y to next line position.
  @table.page.x = orig_x
  @table.page.y = orig_y - @height
end