Class: Docx::Elements::Containers::Table

Inherits:
Object
  • Object
show all
Includes:
Container, Element
Defined in:
lib/docx/containers/table.rb

Constant Summary

Constants included from Element

Element::DEFAULT_TAG

Instance Attribute Summary

Attributes included from Element

#node

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Element

#append_to, #copy, #html_tag, included, #insert_after, #insert_before, #parent, #parent_paragraph, #prepend_to

Methods included from Container

#blank!, #properties, #remove!

Constructor Details

#initialize(node) ⇒ Table

Returns a new instance of Table.



16
17
18
19
# File 'lib/docx/containers/table.rb', line 16

def initialize(node)
  @node = node
  @properties_tag = 'tblGrid'
end

Class Method Details

.tagObject



12
13
14
# File 'lib/docx/containers/table.rb', line 12

def self.tag
  'tbl'
end

Instance Method Details

#column_countObject



39
40
41
# File 'lib/docx/containers/table.rb', line 39

def column_count
  @node.xpath('w:tblGrid/w:gridCol').count
end

#columnsObject

Array of column



31
32
33
34
35
36
37
# File 'lib/docx/containers/table.rb', line 31

def columns
  columns_containers = []
  (0..(column_count-1)).each do |i|
    columns_containers[i] = Containers::TableColumn.new @node.xpath("w:tr//w:tc[#{i+1}]")
  end
  columns_containers
end

#each_rowsObject

Iterate over each row within a table



44
45
46
# File 'lib/docx/containers/table.rb', line 44

def each_rows
  rows.each { |r| yield(r) }
end

#row_countObject



26
27
28
# File 'lib/docx/containers/table.rb', line 26

def row_count
  @node.xpath('w:tr').count
end

#rowsObject

Array of row



22
23
24
# File 'lib/docx/containers/table.rb', line 22

def rows
  @node.xpath('w:tr').map {|r_node| Containers::TableRow.new(r_node) }
end