class OoxmlParser::SharedStringTable

Class for parsing shared string table

Attributes

count[R]

@return [Integer] count of shared strings

string_indexes[R]

@return [Array<StringIndex>] String Index

unique_count[R]

@return [Integer] unique count of shared strings

Public Class Methods

new(parent: nil) click to toggle source
Calls superclass method OoxmlParser::OOXMLDocumentObject::new
# File lib/ooxml_parser/xlsx_parser/workbook/shared_string_table.rb, line 14
def initialize(parent: nil)
  @string_indexes = []
  super
end

Public Instance Methods

parse(file) click to toggle source

Parse Shared string table file @param file [String] path to file @return [SharedStringTable]

# File lib/ooxml_parser/xlsx_parser/workbook/shared_string_table.rb, line 22
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 'count'
      @count = value.value.to_i
    when 'uniqueCount'
      @unique_count = value.value.to_i
    end
  end

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'si'
      @string_indexes << StringIndex.new(parent: self).parse(node_child)
    end
  end
  self
end