Class: OoxmlParser::Table

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/table.rb

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(rows = [], parent: nil) ⇒ Table

Returns a new instance of Table.



10
11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 10

def initialize(rows = [], parent: nil)
  @rows = rows
  @parent = parent
end

Instance Attribute Details

#gridObject

Returns the value of attribute grid.



8
9
10
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 8

def grid
  @grid
end

#numberObject

Returns the value of attribute number.



8
9
10
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 8

def number
  @number
end

#propertiesObject Also known as: table_properties

Returns the value of attribute properties.



8
9
10
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 8

def properties
  @properties
end

#rowsObject

Returns the value of attribute rows.



8
9
10
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 8

def rows
  @rows
end

Instance Method Details

#inspectObject



21
22
23
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 21

def inspect
  to_s
end

#parse(node, number = 0, default_table_properties = TableProperties.new) ⇒ Table

Parse Table object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:

  • (Table)

    result of parsing



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 28

def parse(node,
          number = 0,
          default_table_properties = TableProperties.new)
  table_properties = default_table_properties.dup
  table_properties.jc = :left
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'tblGrid'
      @grid = TableGrid.new(parent: self).parse(node_child)
    when 'tr'
      @rows << TableRow.new(parent: self).parse(node_child)
    when 'tblPr'
      @properties = TableProperties.new(parent: self).parse(node_child)
    end
  end
  @number = number
  self
end

#to_sObject



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 17

def to_s
  "Rows: #{@rows.join(',')}"
end