Sha256: 5c541c2d78fa8b00a84f0d3c8687c02c81db16870d32ac7d207ee00c89171488

Contents?: true

Size: 1.6 KB

Versions: 4

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require 'securerandom'
require 'nokogiri'
require 'zip'
require 'ooxml_decrypt'
require_relative 'ooxml_document_object/nokogiri_parsing_exception'
require_relative 'ooxml_document_object/ooxml_document_object_helper'
require_relative 'ooxml_document_object/ooxml_object_attribute_helper'

module OoxmlParser
  # Basic class for any OOXML Document Object
  class OOXMLDocumentObject
    include OoxmlDocumentObjectHelper
    include OoxmlObjectAttributeHelper
    # @return [OOXMLDocumentObject] object which hold current object
    attr_accessor :parent

    def initialize(parent: nil)
      @parent = parent
    end

    # Compare this object to other
    # @param other [Object] any other object
    # @return [True, False] result of comparision
    def ==(other)
      return false if self.class != other.class

      instance_variables.each do |current_attribute|
        next if current_attribute == :@parent
        next if instance_variable_get(current_attribute).is_a?(Nokogiri::XML::Element)

        return false unless instance_variable_get(current_attribute) == other.instance_variable_get(current_attribute)
      end
      true
    end

    # @return [True, false] if structure contain any user data
    def with_data?
      true
    end

    # @return [Nokogiri::XML::Document] result of parsing xml via nokogiri
    def parse_xml(xml_path)
      xml = Nokogiri::XML(File.open(xml_path), &:strict)
      unless xml.errors.empty?
        raise NokogiriParsingException,
              "Nokogiri found errors in file: #{xml_path}. Errors: #{xml.errors}"
      end
      xml
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ooxml_parser-0.33.0 lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb
ooxml_parser-0.32.0 lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb
ooxml_parser-0.31.0 lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb
ooxml_parser-0.30.0 lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb