Class: OoxmlParser::HeaderFooterChild

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb

Overview

Class for parsing header or footer

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(type: nil, raw_string: nil, parent: nil) ⇒ HeaderFooterChild

Returns a new instance of HeaderFooterChild.



11
12
13
14
15
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb', line 11

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

Instance Attribute Details

#raw_stringString (readonly)

Returns raw text of header.

Returns:

  • (String)

    raw text of header



9
10
11
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb', line 9

def raw_string
  @raw_string
end

#typeSymbol (readonly)

Returns type of header.

Returns:

  • (Symbol)

    type of header



7
8
9
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb', line 7

def type
  @type
end

Instance Method Details

#centerString

Returns center part of header.

Returns:

  • (String)

    center part of header



36
37
38
39
40
41
42
43
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb', line 36

def center
  return @center if @center

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

  @center = center[1]
end

#leftString

Returns left part of header.

Returns:

  • (String)

    left part of header



46
47
48
49
50
51
52
53
54
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb', line 46

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

#parse(node) ⇒ HeaderFooterChild

Parse HeaderFooterChild data

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



20
21
22
23
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb', line 20

def parse(node)
  @raw_string = node.text
  self
end

#rightString

Returns right part of header.

Returns:

  • (String)

    right part of header



26
27
28
29
30
31
32
33
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_header_footer/header_footer_child.rb', line 26

def right
  return @right if @right

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

  @right = right[1]
end