Class: RubyDocx::Elements::TableRow

Inherits:
Element
  • Object
show all
Defined in:
lib/ruby_docx/elements/table_row.rb

Instance Attribute Summary

Attributes inherited from Element

#doc, #grid, #node, #style

Instance Method Summary collapse

Methods inherited from Element

#elements, #initialize, #inspect, #to_xml

Constructor Details

This class inherits a constructor from RubyDocx::Elements::Element

Instance Method Details

#cellsObject



4
5
6
# File 'lib/ruby_docx/elements/table_row.rb', line 4

def cells
  self.elements
end

#to_htmlObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ruby_docx/elements/table_row.rb', line 20

def to_html
  w = 0
  if self.style
    w = self.style.width.to_i
  end

  s = "<tr>"
  self.cells.map do |cell|
    if w.to_i > 0
      s += "<td style='width: #{(w/100.0).round(2)}%'>#{cell.inner_html}</td>"
    else
      s += "<td>#{cell.inner_html}</td>"
    end
  end

  s += "</tr>"

  s
end

#to_sObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ruby_docx/elements/table_row.rb', line 8

def to_s
  s = ""

  self.cells.map do |cell|
    s += "#{cell.to_s}\t"
  end

  s += "\n"

  s
end