class OoxmlParser::OOXMLDocumentObject

Basic class for any OOXML Document Object

Attributes

parent[RW]

@return [OOXMLDocumentObject] object which hold current object

Public Class Methods

new(parent: nil) click to toggle source
# File lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb, line 19
def initialize(parent: nil)
  @parent = parent
end

Public Instance Methods

==(other) click to toggle source

Compare this object to other @param other [Object] any other object @return [True, False] result of comparision

# File lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb, line 26
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
boolean_attribute_value(value) click to toggle source

@param [String, Nokogiri::XML:Attribute] value to check @return [True, False] value of attribute

# File lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb, line 45
def boolean_attribute_value(value)
  return true if value.to_s == '1'
  return true if value.to_s == 'true'
  return false if value.to_s == '0'
  return false if value.to_s == 'false'

  raise ArgumentError, "Invalid value for boolean attribute: #{value}"
end
parse_xml(xml_path) click to toggle source

@return [Nokogiri::XML::Document] result of parsing xml via nokogiri

# File lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb, line 55
def parse_xml(xml_path)
  xml = Nokogiri::XML(File.open(xml_path), &:strict)
  unless xml.errors.empty?
    raise NokogiriParsingException,
          parse_error_message(xml_path, xml.errors)
  end
  xml
rescue  Nokogiri::XML::SyntaxError => e
  raise NokogiriParsingException,
        parse_error_message(xml_path, e)
end
with_data?() click to toggle source

@return [True, false] if structure contain any user data

# File lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb, line 39
def with_data?
  true
end

Private Instance Methods

parse_error_message(xml_path, errors) click to toggle source

@param [String] xml_path path to xml @param [String] errors errors @return [String] error string

# File lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb, line 72
def parse_error_message(xml_path, errors)
  "Nokogiri found errors in file: #{xml_path}. Errors: #{errors}"
end