Sha256: 1287bd9b1361c7057bd5bf4e6f12fbe2098f8f8abff6aa9b89b227d93257916a

Contents?: true

Size: 1.26 KB

Versions: 33

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module OoxmlParser
  # Class for parsing header or footer
  class HeaderFooterChild < OOXMLDocumentObject
    # @return [Symbol] type of header
    attr_reader :type
    # @return [String] raw text of header
    attr_reader :raw_string

    def initialize(type: nil, raw_string: nil, parent: nil)
      @type = type
      @raw_string = raw_string
      super(parent: parent)
    end

    # Parse HeaderFooterChild data
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [HeaderFooterChild] result of parsing
    def parse(node)
      @raw_string = node.text
      self
    end

    # @return [String] right part of header
    def right
      return @right if @right

      right = @raw_string.match(/&R(.+)/)
      return nil unless right

      @right = right[1]
    end

    # @return [String] center part of header
    def center
      return @center if @center

      center = @raw_string.split('&R').first.match(/&C(.+)/)
      return nil unless center

      @center = center[1]
    end

    # @return [String] left part of header
    def left
      return @left if @left

      left = @raw_string.gsub("&R#{right}", '')
      left = left.gsub("&C#{center}", '')
      return nil if left == ''

      left.gsub('&L', '')
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
ooxml_parser-0.38.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.37.1 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.37.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.36.1 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.36.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.35.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.34.2 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.34.1 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.34.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.33.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.32.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.31.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.30.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.29.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.28.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.27.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.26.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.25.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.24.0 lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
ooxml_parser-0.23.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_header_footer/header_footer_child.rb