Class: OoxmlParser::CommonDocumentStructure
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::CommonDocumentStructure
- Defined in:
- lib/ooxml_parser/common_parser/common_document_structure.rb
Overview
Common document structure for DOCX, XLSX, PPTX file
Direct Known Subclasses
Instance Attribute Summary collapse
-
#content_types ⇒ ContentTypes
Data about content types.
-
#default_font_size ⇒ Integer
readonly
Default font size.
-
#default_font_style ⇒ FontStyle
Default font style of presentation.
-
#default_font_typeface ⇒ Integer
readonly
Default font typeface.
-
#file_path ⇒ String
Path to original file.
-
#root_subfolder ⇒ String
readonly
Root sub-folder for object.
-
#unpacked_folder ⇒ String
readonly
Path to folder with unpacked document.
-
#xmls_stack ⇒ Array<String>
List of xmls to parse.
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
-
#add_to_xmls_stack(path) ⇒ void
Add file to parsing stack.
-
#current_xml ⇒ String
Path to current xml file.
-
#get_link_from_rels(id) ⇒ String
Get link to file from rels file.
-
#initialize(params = {}) ⇒ CommonDocumentStructure
constructor
A new instance of CommonDocumentStructure.
Methods inherited from OOXMLDocumentObject
#==, #boolean_attribute_value, #parse_xml, #with_data?
Methods included from OoxmlObjectAttributeHelper
#attribute_enabled?, #option_enabled?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(params = {}) ⇒ CommonDocumentStructure
Returns a new instance of 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_types ⇒ ContentTypes
Returns data about content types.
16 17 18 |
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 16 def content_types @content_types end |
#default_font_size ⇒ Integer (readonly)
Returns default font size.
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_style ⇒ FontStyle
Returns Default font style of presentation.
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_typeface ⇒ Integer (readonly)
Returns default font typeface.
12 13 14 |
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 12 def default_font_typeface @default_font_typeface end |
#file_path ⇒ String
Returns path to original file.
8 9 10 |
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 8 def file_path @file_path end |
#root_subfolder ⇒ String (readonly)
Returns root sub-folder for object.
18 19 20 |
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 18 def root_subfolder @root_subfolder end |
#unpacked_folder ⇒ String (readonly)
Returns path to folder with unpacked document.
20 21 22 |
# File 'lib/ooxml_parser/common_parser/common_document_structure.rb', line 20 def unpacked_folder @unpacked_folder end |
#xmls_stack ⇒ Array<String>
Returns list of xmls to parse.
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_xml ⇒ String
Returns path to current xml file.
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_from_rels(id) ⇒ String
Get link to file from rels file
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 |