class OoxmlParser::CommonDocumentStructure
Common document structure for DOCX, XLSX, PPTX file
Attributes
content_types[RW]
@return [ContentTypes] data about content types
default_font_size[R]
@return [Integer] default font size
default_font_style[RW]
@return [FontStyle] Default font style of presentation
default_font_typeface[R]
@return [Integer] default font typeface
file_path[RW]
@return [String] path to original file
root_subfolder[R]
@return [String] root sub-folder for object
unpacked_folder[R]
@return [String] path to folder with unpacked document
xmls_stack[RW]
@return [Array<String>] list of xmls to parse
Public Class Methods
new(params = {})
click to toggle source
Calls superclass method
OoxmlParser::OOXMLDocumentObject::new
# 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
Public Instance Methods
add_to_xmls_stack(path)
click to toggle source
Add file to parsing stack @param path [String] path of file to add to stack @return [void]
# 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_xml()
click to toggle source
@return [String] path to current xml file
# 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_from_rels(id)
click to toggle source
Get link to file from rels file @param id [String] file to get @return [String] result
# 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
Private Instance Methods
cache_relationships(rels_path)
click to toggle source
Store relationships to cache
# File lib/ooxml_parser/common_parser/common_document_structure.rb, line 67 def cache_relationships(rels_path) return if @relationships_cache.key?(rels_path) @relationships_cache[rels_path] = Relationships.new.parse_file(rels_path) end