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, #at_xpath, #copy, #html_tag, included, #insert_after, #insert_before, #parent, #parent_paragraph, #prepend_to, #xpath

Methods included from Container

#blank!, #properties, #remove!

Constructor Details

#initialize(node, document_properties = {}, doc = nil) ⇒ Table

Returns a new instance of Table.



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

def initialize(node, document_properties = {}, doc = nil)
  @node = node
  @properties_tag = 'tblGrid'
  @document_properties = document_properties
  @document = doc
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



41
42
43
# File 'lib/docx/containers/table.rb', line 41

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

#columnsObject

Array of column



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

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}]"), @document_properties, @document)
  end
  columns_containers
end

#each_rowsObject

Iterate over each row within a table



46
47
48
# File 'lib/docx/containers/table.rb', line 46

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

#row_countObject



28
29
30
# File 'lib/docx/containers/table.rb', line 28

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

#rowsObject

Array of row



24
25
26
# File 'lib/docx/containers/table.rb', line 24

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