Class: WizRtf::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/wiz_rtf/cell.rb

Overview

Represents a table cell.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cell) ⇒ Cell

This is the constructor for the Cell class.

  • cell - optional values

    number, string, symbol, hash.

Example:

WizRtf::Cell.new(rowspan:3, colspan:2)



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wiz_rtf/cell.rb', line 19

def initialize(cell)
  if cell.is_a?(Hash)
    @colspan = cell[:colspan] || 1
    @rowspan = cell[:rowspan] || 1
    @content = cell[:content] || ''
  else
    @colspan = 1
    @rowspan = 1
    @content = cell
  end
end

Instance Attribute Details

#colspanObject

Returns the value of attribute colspan.



11
12
13
# File 'lib/wiz_rtf/cell.rb', line 11

def colspan
  @colspan
end

#contentObject

Returns the value of attribute content.



11
12
13
# File 'lib/wiz_rtf/cell.rb', line 11

def content
  @content
end

#right_widthObject

Returns the value of attribute right_width.



11
12
13
# File 'lib/wiz_rtf/cell.rb', line 11

def right_width
  @right_width
end

#rowspanObject

Returns the value of attribute rowspan.



11
12
13
# File 'lib/wiz_rtf/cell.rb', line 11

def rowspan
  @rowspan
end

#v_mergeObject

Returns the value of attribute v_merge.



11
12
13
# File 'lib/wiz_rtf/cell.rb', line 11

def v_merge
  @v_merge
end

Instance Method Details

#render(io) ⇒ Object

Outputs the Partial Rtf Document to a Generic Stream as a Rich Text Format (RTF).

  • io - The Generic IO to Output the RTF Document.



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
# File 'lib/wiz_rtf/cell.rb', line 33

def render(io)
  io.cmd :celld
  io.cmd :clbrdrt
  io.cmd :brdrs
  io.cmd :brdrw10
  io.cmd :clbrdrl
  io.cmd :brdrs
  io.cmd :brdrw10
  io.cmd :clbrdrb
  io.cmd :brdrs
  io.cmd :brdrw10
  io.cmd :clbrdrr
  io.cmd :brdrs
  io.cmd :brdrw10
  io.cmd  v_merge if v_merge
  io.cmd :cellx, right_width
  contents = [@content] unless @content.is_a?(Array)
  contents.each do |c|
    if c.respond_to?(:render)
      c.render(io)
    else
      io.txt c
    end
  end
  io.cmd :cell
end