module OoxmlParser::OoxmlDocumentObjectHelper

Module for helper methods for OOXMLDocumentObject

Constants

VALUE_TO_SYMBOL_HASH

Public Instance Methods

to_hash() click to toggle source

Convert object to hash @return [Hash]

# File lib/ooxml_parser/common_parser/common_data/ooxml_document_object/ooxml_document_object_helper.rb, line 8
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

Private Instance Methods

root_object() click to toggle source
# File lib/ooxml_parser/common_parser/common_data/ooxml_document_object/ooxml_document_object_helper.rb, line 111
def root_object
  tree_object = self
  tree_object = tree_object.parent until tree_object.parent.nil?
  tree_object
end
value_to_symbol(value) click to toggle source

Convert value to human readable symbol @param [String] value to convert @return [Symbol]

# File lib/ooxml_parser/common_parser/common_data/ooxml_document_object/ooxml_document_object_helper.rb, line 104
def value_to_symbol(value)
  symbol = VALUE_TO_SYMBOL_HASH[value.value.to_sym]
  return value.value.to_sym if symbol.nil?

  symbol
end