Class: Prune::Parsers::TrParser
- Defined in:
- lib/prune/parsers/document/page/table/tr_parser.rb
Overview
Parser for directive “tr”.
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(table, options = {}) ⇒ TrParser
constructor
Initialize.
-
#render ⇒ Object
Render td tags.
Methods included from Prune::PObjects
Methods included from Functions
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, = {}) @table = table @options = # Boundary of this object. @x = @table.page.x @y = @table.page.y @width = 0.0 @height = 0.0 @widths = [:widths] || @table.[:widths] || [] # All td tags inside this tag. @tds = [] end |
Instance Attribute Details
#height ⇒ Object (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 |
#width ⇒ Object (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 |
#x ⇒ Object (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 |
#y ⇒ Object (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
#render ⇒ Object
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 |