Class: DocXify::Element::TableCell
- Defined in:
- lib/docxify/element/table_cell.rb
Instance Attribute Summary collapse
-
#align ⇒ Object
Returns the value of attribute align.
-
#borders ⇒ Object
Returns the value of attribute borders.
-
#colour ⇒ Object
Returns the value of attribute colour.
-
#colspan ⇒ Object
Returns the value of attribute colspan.
-
#content ⇒ Object
Returns the value of attribute content.
-
#font ⇒ Object
Returns the value of attribute font.
-
#nowrap ⇒ Object
Returns the value of attribute nowrap.
-
#size ⇒ Object
Returns the value of attribute size.
-
#valign ⇒ Object
Returns the value of attribute valign.
-
#width_cm ⇒ Object
Returns the value of attribute width_cm.
Instance Method Summary collapse
-
#initialize(content, options = {}) ⇒ TableCell
constructor
A new instance of TableCell.
- #to_s ⇒ Object
Constructor Details
#initialize(content, options = {}) ⇒ TableCell
Returns a new instance of TableCell.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/docxify/element/table_cell.rb', line 6 def initialize(content, = {}) super() @content = content @valign = [:valign] || :top @align = [:align] || :left @nowrap = [:nowrap] @colspan = [:colspan] @rowspan = [:rowspan] @width_cm = [:width_cm] @font = [:font] @size = [:size] @color = [:color] @borders = [:borders]&.map(&:to_sym) || [] end |
Instance Attribute Details
#align ⇒ Object
Returns the value of attribute align.
4 5 6 |
# File 'lib/docxify/element/table_cell.rb', line 4 def align @align end |
#borders ⇒ Object
Returns the value of attribute borders.
4 5 6 |
# File 'lib/docxify/element/table_cell.rb', line 4 def borders @borders end |
#colour ⇒ Object
Returns the value of attribute colour.
4 5 6 |
# File 'lib/docxify/element/table_cell.rb', line 4 def colour @colour end |
#colspan ⇒ Object
Returns the value of attribute colspan.
4 5 6 |
# File 'lib/docxify/element/table_cell.rb', line 4 def colspan @colspan end |
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/docxify/element/table_cell.rb', line 4 def content @content end |
#font ⇒ Object
Returns the value of attribute font.
4 5 6 |
# File 'lib/docxify/element/table_cell.rb', line 4 def font @font end |
#nowrap ⇒ Object
Returns the value of attribute nowrap.
4 5 6 |
# File 'lib/docxify/element/table_cell.rb', line 4 def nowrap @nowrap end |
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'lib/docxify/element/table_cell.rb', line 4 def size @size end |
#valign ⇒ Object
Returns the value of attribute valign.
4 5 6 |
# File 'lib/docxify/element/table_cell.rb', line 4 def valign @valign end |
#width_cm ⇒ Object
Returns the value of attribute width_cm.
4 5 6 |
# File 'lib/docxify/element/table_cell.rb', line 4 def width_cm @width_cm end |
Instance Method Details
#to_s ⇒ Object
21 22 23 24 25 26 27 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 55 56 57 58 59 60 61 62 63 |
# File 'lib/docxify/element/table_cell.rb', line 21 def to_s xml = "<w:tc>" xml << "<w:tcPr>" xml << %Q(<w:tcW w:type="dxa" w:w="#{DocXify.cm2dxa(@width_cm)}"/>) if !@colspan.nil? && @colspan.to_i > 1 xml << %Q(<w:gridSpan w:val="#{@colspan}"/>') end if borders.any? xml << "<w:tcBorders>" xml << (borders.include?(:top) ? '<w:top w:color="auto" w:space="0" w:sz="4" w:val="single"/>' : '<w:top w:val="nil"/>') xml << (borders.include?(:bottom) ? '<w:bottom w:color="auto" w:space="0" w:sz="4" w:val="single"/>' : '<w:bottom w:val="nil"/>') xml << (borders.include?(:left) ? '<w:left w:color="auto" w:space="0" w:sz="4" w:val="single"/>' : '<w:left w:val="nil"/>') xml << (borders.include?(:right) ? '<w:right w:color="auto" w:space="0" w:sz="4" w:val="single"/>' : '<w:right w:val="nil"/>') xml << "</w:tcBorders>" end if @valign != :top xml << %Q(<w:vAlign w:val="#{@valign}"/>) end if @nowrap xml << "<w:noWrap/>" end if @content.nil? @content = "" # Nil is useful for rowspan, but we need to output something or Word breaks end if @rowspan xml << '<w:vMerge w:val="restart"/>' elsif @content == "" xml << "<w:vMerge/>" end xml << "</w:tcPr>" xml << DocXify::Element::Paragraph.new(@content, document: @document, font: @font, size: @size, color: @color, align: @align).to_s xml << "</w:tc>" xml end |