Class: OoxmlParser::TableCell

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

Overview

Class for parsing ‘tc` tags

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(parent: nil) ⇒ TableCell

Returns a new instance of TableCell.



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

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

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb', line 6

def elements
  @elements
end

#grid_spanObject

Returns the value of attribute grid_span.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb', line 6

def grid_span
  @grid_span
end

#horizontal_mergeObject

Returns the value of attribute horizontal_merge.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb', line 6

def horizontal_merge
  @horizontal_merge
end

#propertiesObject Also known as: cell_properties

Returns the value of attribute properties.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb', line 6

def properties
  @properties
end

#text_bodyObject

Returns the value of attribute text_body.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb', line 6

def text_body
  @text_body
end

#vertical_mergeObject

Returns the value of attribute vertical_merge.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb', line 6

def vertical_merge
  @vertical_merge
end

Instance Method Details

#parse(node) ⇒ TableCell

Parse TableCell object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb', line 18

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'gridSpan'
      @grid_span = value.value.to_i
    when 'hMerge'
      @horizontal_merge = value.value.to_i
    when 'vMerge'
      @vertical_merge = value.value.to_i
    end
  end

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'txBody'
      @text_body = TextBody.new(parent: self).parse(node_child)
    when 'tcPr'
      @properties = CellProperties.new(parent: self).parse(node_child)
    when 'p'
      @elements << DocumentStructure.default_table_paragraph_style.dup.parse(node_child,
                                                                             0,
                                                                             DocumentStructure.default_table_run_style,
                                                                             parent: self)
    when 'tbl'
      @elements << Table.new(parent: self).parse(node_child)
    end
  end
  self
end