Class: OoxmlParser::PageProperties

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb

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) ⇒ PageProperties

Returns a new instance of PageProperties.



16
17
18
19
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 16

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

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



9
10
11
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 9

def columns
  @columns
end

#document_gridObject

Returns the value of attribute document_grid.



9
10
11
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 9

def document_grid
  @document_grid
end

#footnote_propertiesFootnoteProperties

Returns properties of footnote.

Returns:



12
13
14
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 12

def footnote_properties
  @footnote_properties
end

#form_protObject

Returns the value of attribute form_prot.



9
10
11
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 9

def form_prot
  @form_prot
end

#marginsObject

Returns the value of attribute margins.



9
10
11
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 9

def margins
  @margins
end

#notesObject

Returns the value of attribute notes.



9
10
11
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 9

def notes
  @notes
end

#num_typeObject

Returns the value of attribute num_type.



9
10
11
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 9

def num_type
  @num_type
end

#page_bordersObject

Returns the value of attribute page_borders.



9
10
11
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 9

def page_borders
  @page_borders
end

#sizeObject

Returns the value of attribute size.



9
10
11
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 9

def size
  @size
end

#text_directionObject

Returns the value of attribute text_direction.



9
10
11
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 9

def text_direction
  @text_direction
end

#title_pageTrue, False (readonly)

Returns Specifies whether the section should have a different header and footer for its first page.

Returns:

  • (True, False)

    Specifies whether the section should have a different header and footer for its first page



14
15
16
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 14

def title_page
  @title_page
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 9

def type
  @type
end

Instance Method Details

#parse(node, default_paragraph, default_character) ⇒ PageProperties

Parse PageProperties data

Parameters:

  • node (Nokogiri::XML:Element)

    with PageProperties data

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb', line 24

def parse(node, default_paragraph, default_character)
  node.xpath('*').each do |pg_size_subnode|
    case pg_size_subnode.name
    when 'pgSz'
      @size = PageSize.new.parse(pg_size_subnode)
    when 'pgBorders'
      page_borders = Borders.new
      page_borders.display = pg_size_subnode.attribute('display').value.to_sym unless pg_size_subnode.attribute('display').nil?
      page_borders.offset_from = pg_size_subnode.attribute('offsetFrom').value.to_sym unless pg_size_subnode.attribute('offsetFrom').nil?
      pg_size_subnode.xpath('w:bottom').each do |bottom|
        page_borders.bottom = BordersProperties.new(parent: page_borders).parse(bottom)
      end
      pg_size_subnode.xpath('w:left').each do |left|
        page_borders.bottom = BordersProperties.new(parent: page_borders).parse(left)
      end
      pg_size_subnode.xpath('w:top').each do |top|
        page_borders.bottom = BordersProperties.new(parent: page_borders).parse(top)
      end
      pg_size_subnode.xpath('w:right').each do |right|
        page_borders.bottom = BordersProperties.new(parent: page_borders).parse(right)
      end
      @page_borders = page_borders
    when 'type'
      @type = pg_size_subnode.attribute('val').value
    when 'pgMar'
      @margins = PageMargins.new(parent: self).parse(pg_size_subnode)
    when 'pgNumType'
      @num_type = pg_size_subnode.attribute('fmt').value unless pg_size_subnode.attribute('fmt').nil?
    when 'formProt'
      @form_prot = pg_size_subnode.attribute('val').value
    when 'textDirection'
      @text_direction = pg_size_subnode.attribute('val').value
    when 'docGrid'
      @document_grid = DocumentGrid.new(parent: self).parse(pg_size_subnode)
    when 'titlePg'
      @title_page = option_enabled?(pg_size_subnode)
    when 'cols'
      @columns = Columns.new.parse(pg_size_subnode)
    when 'headerReference', 'footerReference'
      target = OOXMLDocumentObject.get_link_from_rels(pg_size_subnode.attribute('id').value)
      OOXMLDocumentObject.add_to_xmls_stack("word/#{target}")
      note = Note.parse(default_paragraph: default_paragraph,
                        default_character: default_character,
                        target: target,
                        assigned_to: pg_size_subnode.attribute('type').value,
                        type: File.basename(target).sub('.xml', ''),
                        parent: self)
      @notes << note
      OOXMLDocumentObject.xmls_stack.pop
    when 'footnotePr'
      @footnote_properties = FootnoteProperties.new(parent: self).parse(pg_size_subnode)
    end
  end
  self
end