Sha256: d487828abd72db62f0b77fddf6c0c1ce58e4ab096e31e58bf90b6100f33d2917

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require_relative 'table/row/row'
require_relative 'table/table_properties'
require_relative 'table/table_grid'
require_relative 'table/margins/table_margins'
require_relative 'table/margins/paragraph_margins'
module OoxmlParser
  # Class for Table data
  class Table < OOXMLDocumentObject
    attr_accessor :grid, :rows, :properties, :number

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

    alias table_properties properties

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

    def inspect
      to_s
    end

    # Parse Table object
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [Table] result of parsing
    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ooxml_parser-0.6.0 lib/ooxml_parser/common_parser/common_data/table.rb
ooxml_parser-0.5.1 lib/ooxml_parser/common_parser/common_data/table.rb
ooxml_parser-0.5.0 lib/ooxml_parser/common_parser/common_data/table.rb