Class: OoxmlParser::OOXMLDocumentObject
- Inherits:
-
Object
- Object
- OoxmlParser::OOXMLDocumentObject
- Includes:
- OoxmlDocumentObjectHelper
- Defined in:
- lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb
Direct Known Subclasses
AbstractNumbering, AbstractNumberingId, Accent, AlphaModFix, AlternateContent, AnimationEffect, ArgumentProperties, ArgumentSize, Autofilter, Background, BackgroundProperties, Bar, Behavior, Blip, BlipFill, Bookmark, Border, BordersProperties, Box, CellProperties, CellStyle, Chart, ChartAxis, ChartAxisTitle, ChartCellsRange, ChartLegend, ChartStyle, Chartsheet, Choice, Color, ColorProperties, Column, Columns, Comment, CommentExtended, CommentsExtended, CommonDocumentStructure, CommonNonVisualProperties, CommonSlideData, Condition, Delimiter, DisplayLabelsProperties, DocProperties, DocumentBackground, DocumentDefaults, DocumentGrid, DocumentProperties, DocumentSettings, DocumentStyle, DocxBlip, DocxColor, DocxColorScheme, DocxDrawing, DocxDrawingDistanceFromText, DocxDrawingPosition, DocxDrawingProperties, DocxFormula, DocxGraphic, DocxParagraph, DocxParagraphRun, DocxPatternFill, DocxPicture, DocxShape, DocxShapeLine, DocxShapeLineElement, DocxShapeLinePath, DocxShapeProperties, DocxShapeSize, DocxWrapDrawing, ExcelComment, Extension, ExtensionList, FileReference, Fill, Fills, FilterColumn, Font, Fonts, FootnoteProperties, Fraction, FrameProperties, Function, GradientStop, GraphicFrame, GridColumn, GroupChar, HeaderFooter, Hyperlink, HyperlinkForHover, ImageFill, Indents, Index, Inserted, Language, LevelJustification, LevelText, Limit, LineEnd, LineJoin, LinearGradient, MathParagraph, MathRun, MathRunProperties, MathText, Matrix, MatrixRow, MultilevelType, Nary, NaryGrow, NaryLimitLocation, NaryProperties, NonVisualProperties, NonVisualShapeProperties, Note, NumberFormat, NumberFormats, Numbering, NumberingDefinition, NumberingFormat, NumberingLevel, NumberingProperties, OOXMLCustomGeometry, OOXMLShapeBodyProperties, OOXMLTextBox, OldDocxGroup, OldDocxPicture, OldDocxShape, OldDocxShapeFill, OldDocxShapeProperties, OleObject, OleObjects, OoxmlColor, Order, Outline, PageMargins, PageProperties, PageSize, Pane, Paragraph, ParagraphBorders, ParagraphProperties, ParagraphPropertiesDefault, ParagraphRun, ParagraphSpacing, PatternFill, PictureDimension, Point, PointCount, Position, PreSubSuperscript, PresentationAlternateContent, PresentationComment, PresentationCommentAuthor, PresentationFill, PresentationNotes, PresentationPattern, PresentationTheme, PresetColor, PresetGeometry, PresetTextWarp, Radical, Relationship, RunObject, RunProperties, RunPropertiesDefault, RunSpacing, RunStyle, SDTContent, SDTProperties, Scaling, Series, SeriesIndex, SeriesText, SetTimeNode, Shade, Shape, ShapeAdjustValueList, ShapeGuide, ShapePlaceholder, ShapeTree, ShapesGrouping, SheetFormatProperties, SheetView, Size, SizeRelativeHorizontal, SizeRelativeVertical, Slide, SlideSize, Sound, SoundAction, SparklineGroup, SparklineGroups, Start, Stretch, StringCache, StringReference, StructuredDocumentTag, StyleParametres, StyleSheet, Styles, Suffix, Tab, Table, TableBorders, TableCell, TableCellLine, TableElement, TableGrid, TableLayout, TableLook, TableMargins, TablePart, TablePosition, TableProperties, TableRow, TableRowHeight, TableRowProperties, TableStyle, TableStyleColumnBandSize, TableStyleInfo, TableStyleProperties, TableStyleRowBandSize, Tabs, TargetElement, Text, TextBody, TextField, TextFill, TextOutline, TextValue, ThemeColor, Tile, TimeNode, Timing, Transition, TransitionProperties, Underline, ValuedChild, VerticalMerge, View3D, Worksheet, X14Table, XlsxAlignment, XlsxCell, XlsxColumnProperties, XlsxDrawing, XlsxDrawingPositionParameters, XlsxRow
Class Attribute Summary collapse
-
.path_to_folder ⇒ Object
Returns the value of attribute path_to_folder.
-
.root_subfolder ⇒ Object
Returns the value of attribute root_subfolder.
-
.theme ⇒ Object
Returns the value of attribute theme.
-
.xmls_stack ⇒ Object
Returns the value of attribute xmls_stack.
Instance Attribute Summary collapse
-
#parent ⇒ OOXMLDocumentObject
Object which hold current object.
Class Method Summary collapse
- .add_to_xmls_stack(path) ⇒ Object
- .copy_file_and_rename_to_zip(path) ⇒ Object
- .current_xml ⇒ Object
- .dir ⇒ Object
-
.encrypted_file?(path_to_file) ⇒ True, False
Check if file is protected by password on open.
- .get_link_from_rels(id) ⇒ Object
- .unzip_file(path_to_file, destination) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(parent: nil) ⇒ OOXMLDocumentObject
constructor
A new instance of OOXMLDocumentObject.
-
#with_data? ⇒ True, false
If structure contain any user data.
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(parent: nil) ⇒ OOXMLDocumentObject
Returns a new instance of OOXMLDocumentObject.
13 14 15 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 13 def initialize(parent: nil) @parent = parent end |
Class Attribute Details
.path_to_folder ⇒ Object
Returns the value of attribute path_to_folder.
34 35 36 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 34 def path_to_folder @path_to_folder end |
.root_subfolder ⇒ Object
Returns the value of attribute root_subfolder.
31 32 33 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 31 def root_subfolder @root_subfolder end |
.theme ⇒ Object
Returns the value of attribute theme.
32 33 34 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 32 def theme @theme end |
.xmls_stack ⇒ Object
Returns the value of attribute xmls_stack.
33 34 35 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 33 def xmls_stack @xmls_stack end |
Instance Attribute Details
#parent ⇒ OOXMLDocumentObject
Returns object which hold current object.
11 12 13 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 11 def parent @parent end |
Class Method Details
.add_to_xmls_stack(path) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 83 def add_to_xmls_stack(path) OOXMLDocumentObject.xmls_stack << if path.include?('..') "#{File.dirname(OOXMLDocumentObject.xmls_stack.last)}/#{path}" elsif path.start_with?(OOXMLDocumentObject.root_subfolder) path else OOXMLDocumentObject.root_subfolder + path end end |
.copy_file_and_rename_to_zip(path) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 52 def copy_file_and_rename_to_zip(path) file_name = File.basename(path) tmp_folder = Dir.mktmpdir('ruby-ooxml-parser') file_path = "#{tmp_folder}/#{file_name}" FileUtils.rm_rf(tmp_folder) if File.directory?(tmp_folder) FileUtils.mkdir_p(tmp_folder) raise "Cannot find file by path #{path}" unless File.exist?(path) FileUtils.cp path, tmp_folder file_path end |
.current_xml ⇒ Object
79 80 81 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 79 def current_xml OOXMLDocumentObject.path_to_folder + OOXMLDocumentObject.xmls_stack.last end |
.dir ⇒ Object
75 76 77 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 75 def dir OOXMLDocumentObject.path_to_folder + File.dirname(OOXMLDocumentObject.xmls_stack.last) + '/' end |
.encrypted_file?(path_to_file) ⇒ True, False
Returns Check if file is protected by password on open.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 38 def encrypted_file?(path_to_file) file_result = FileMagic.new(:mime).file(path_to_file) # Support of Encrtypted status in `file` util was introduced in file v5.20 # but LTS version of ubuntu before 16.04 uses older `file` and it return `Composite Document` # https://github.com/file/file/blob/master/ChangeLog#L217 if file_result.include?('encrypted') || file_result.include?('Composite Document File V2 Document, No summary info') || file_result.include?('application/CDFV2-corrupt') warn("File #{path_to_file} is encrypted. Can't parse it") return true end false end |
.get_link_from_rels(id) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 93 def get_link_from_rels(id) rels_path = dir + "_rels/#{File.basename(OOXMLDocumentObject.xmls_stack.last)}.rels" raise LoadError, "Cannot find .rels file by path: #{rels_path}" unless File.exist?(rels_path) relationships = Relationships.parse_rels(rels_path) relationships.target_by_id(id) end |
.unzip_file(path_to_file, destination) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 63 def unzip_file(path_to_file, destination) Zip.warn_invalid_date = false Zip::File.open(path_to_file) do |zip_file| raise LoadError, "There is no files in zip #{path_to_file}" if zip_file.entries.empty? zip_file.each do |file| file_path = File.join(destination, file.name) FileUtils.mkdir_p(File.dirname(file_path)) zip_file.extract(file, file_path) unless File.exist?(file_path) end end end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 17 def ==(other) instance_variables.each do |current_attribute| next if current_attribute == :@parent return false unless instance_variable_get(current_attribute) == other.instance_variable_get(current_attribute) end true end |
#with_data? ⇒ True, false
Returns if structure contain any user data.
26 27 28 |
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb', line 26 def with_data? true end |