Class: Coradoc::Element::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/element/table.rb

Defined Under Namespace

Classes: Cell, Row

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#children_accessors, children_accessors, declare_children, #simplify_block_content, visit, #visit

Constructor Details

#initialize(title, rows, options = {}) ⇒ Table

Returns a new instance of Table.



8
9
10
11
12
13
14
# File 'lib/coradoc/element/table.rb', line 8

def initialize(title, rows, options = {})
  @rows = rows
  @title = title
  @id = options.fetch(:id, nil)
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
  @attrs = options.fetch(:attributes, nil)
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/coradoc/element/table.rb', line 4

def content
  @content
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/coradoc/element/table.rb', line 4

def id
  @id
end

#rowsObject

Returns the value of attribute rows.



4
5
6
# File 'lib/coradoc/element/table.rb', line 4

def rows
  @rows
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/coradoc/element/table.rb', line 4

def title
  @title
end

Instance Method Details

#to_adocObject



16
17
18
19
20
21
22
23
# File 'lib/coradoc/element/table.rb', line 16

def to_adoc
  anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
  attrs = @attrs.to_s.empty? ? "" : "#{@attrs.to_adoc}\n"
  title = Coradoc::Generator.gen_adoc(@title)
  title = title.empty? ? "" : ".#{title}\n"
  content = @rows.map(&:to_adoc).join
  "\n\n#{anchor}#{attrs}#{title}|===\n" << content << "\n|===\n"
end