Module: OoxmlDocumentObjectHelper

Included in:
OoxmlParser::OOXMLDocumentObject
Defined in:
lib/ooxml_parser/common_parser/common_data/ooxml_document_object/ooxml_document_object_helper.rb

Overview

Module for helper methods for OOXMLDocumentObject

Instance Method Summary collapse

Instance Method Details

#to_hashHash

Convert object to hash

Returns:

  • (Hash)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ooxml_parser/common_parser/common_data/ooxml_document_object/ooxml_document_object_helper.rb', line 5

def to_hash
  result_hash = {}
  instance_variables.each do |current_attribute|
    next if current_attribute == :@parent
    attribute_value = instance_variable_get(current_attribute)
    next unless attribute_value
    if attribute_value.is_a?(Array)
      attribute_value.each_with_index do |object_element, index|
        result_hash["#{current_attribute}_#{index}".to_sym] = object_element.to_hash
      end
    else
      result_hash[current_attribute.to_sym] = if attribute_value.respond_to?(:to_hash)
                                                attribute_value.to_hash
                                              else
                                                attribute_value.to_s
                                              end
    end
  end
  result_hash
end