Class: OoxmlParser::CommonDocumentStructure

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_document_structure.rb

Overview

Common document structure for DOCX, XLSX, PPTX file

Direct Known Subclasses

DocumentStructure, Presentation, XLSXWorkbook

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(params = {}) ⇒ CommonDocumentStructure



24
25
26
27
28
29
30
31
32
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 24

def initialize(params = {})
  @default_font_size = params.fetch(:default_font_size, 18)
  @default_font_typeface = params.fetch(:default_font_typeface, 'Arial')
  @default_font_style = FontStyle.new
  @unpacked_folder = params.fetch(:unpacked_folder, nil)
  @xmls_stack = []
  @relationships_cache = {}
  super(parent: nil)
end

Instance Attribute Details

#content_typesContentTypes



16
17
18
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 16

def content_types
  @content_types
end

#default_font_sizeInteger (readonly)



10
11
12
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 10

def default_font_size
  @default_font_size
end

#default_font_styleFontStyle



14
15
16
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 14

def default_font_style
  @default_font_style
end

#default_font_typefaceInteger (readonly)



12
13
14
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 12

def default_font_typeface
  @default_font_typeface
end

#file_pathString



8
9
10
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 8

def file_path
  @file_path
end

#root_subfolderString (readonly)



18
19
20
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 18

def root_subfolder
  @root_subfolder
end

#unpacked_folderString (readonly)



20
21
22
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 20

def unpacked_folder
  @unpacked_folder
end

#xmls_stackArray<String>



22
23
24
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 22

def xmls_stack
  @xmls_stack
end

Instance Method Details

#add_to_xmls_stack(path) ⇒ void

This method returns an undefined value.

Add file to parsing stack



42
43
44
45
46
47
48
49
50
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 42

def add_to_xmls_stack(path)
  @xmls_stack << if path.include?('..')
                   "#{File.dirname(@xmls_stack.last)}/#{path}"
                 elsif path.start_with?(@root_subfolder)
                   path
                 else
                   @root_subfolder + path
                 end
end

#current_xmlString



35
36
37
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 35

def current_xml
  root_object.unpacked_folder + @xmls_stack.last
end

Get link to file from rels file

Raises:

  • (LoadError)


55
56
57
58
59
60
61
62
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 55

def get_link_from_rels(id)
  dir = "#{unpacked_folder}#{File.dirname(@xmls_stack.last)}/"
  rels_path = dir + "_rels/#{File.basename(@xmls_stack.last)}.rels"
  raise LoadError, "Cannot find .rels file by path: #{rels_path}" unless File.exist?(rels_path)

  cache_relationships(rels_path)
  @relationships_cache[rels_path].target_by_id(id)
end