Class: OoxmlParser::Table

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

Overview

Class for Table data

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

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

Returns a new instance of Table.



13
14
15
16
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 13

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

Instance Attribute Details

#gridObject

Returns the value of attribute grid.



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

def grid
  @grid
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#propertiesObject Also known as: table_properties

Returns the value of attribute properties.



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

def properties
  @properties
end

#rowsObject

Returns the value of attribute rows.



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

def rows
  @rows
end

Instance Method Details

#inspectString

Returns inspect of object for debug means.

Returns:

  • (String)

    inspect of object for debug means



26
27
28
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 26

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ooxml_parser/common_parser/common_data/table.rb', line 33

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_sString

Returns result of convert of object to string.

Returns:

  • (String)

    result of convert of object to string



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

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