Class: OoxmlParser::PivotCacheDefinition

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/xlsx_parser/workbook/pivot_cache/pivot_cache_definition.rb

Overview

Class for parsing <pivotCacheDefinition> file

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #initialize, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

This class inherits a constructor from OoxmlParser::OOXMLDocumentObject

Instance Attribute Details

#cache_fieldsCacheFields (readonly)

Returns fields of pivot cache.

Returns:



14
15
16
# File 'lib/ooxml_parser/xlsx_parser/workbook/pivot_cache/pivot_cache_definition.rb', line 14

def cache_fields
  @cache_fields
end

#cache_sourceCacheSource (readonly)

Returns source of pivot cache.

Returns:



12
13
14
# File 'lib/ooxml_parser/xlsx_parser/workbook/pivot_cache/pivot_cache_definition.rb', line 12

def cache_source
  @cache_source
end

#idString (readonly)

Returns id of pivot cache definition.

Returns:

  • (String)

    id of pivot cache definition



10
11
12
# File 'lib/ooxml_parser/xlsx_parser/workbook/pivot_cache/pivot_cache_definition.rb', line 10

def id
  @id
end

Instance Method Details

#parse(file) ⇒ PivotCacheDefinition

Parse PivotCacheDefinition file

Parameters:

  • file (String)

    path to file

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ooxml_parser/xlsx_parser/workbook/pivot_cache/pivot_cache_definition.rb', line 19

def parse(file)
  return nil unless File.exist?(file)

  document = parse_xml(file)
  node = document.xpath('*').first

  node.attributes.each do |key, value|
    case key
    when 'id'
      @id = value.value.to_s
    end
  end

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'cacheSource'
      @cache_source = CacheSource.new(parent: self).parse(node_child)
    when 'cacheFields'
      @cache_fields = CacheFields.new(parent: self).parse(node_child)
    end
  end
  self
end