Class: OoxmlParser::SharedStringTable
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::SharedStringTable
- Defined in:
- lib/ooxml_parser/xlsx_parser/workbook/shared_string_table.rb
Overview
Class for parsing shared string table
Instance Attribute Summary collapse
-
#count ⇒ Integer
readonly
Count of shared strings.
-
#string_indexes ⇒ Array<StringIndex>
readonly
String Index.
-
#unique_count ⇒ Integer
readonly
Unique count of shared strings.
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
-
#initialize(parent: nil) ⇒ SharedStringTable
constructor
A new instance of SharedStringTable.
-
#parse(file) ⇒ SharedStringTable
Parse Shared string table file.
Methods inherited from OOXMLDocumentObject
#==, #boolean_attribute_value, #parse_xml, #with_data?
Methods included from OoxmlObjectAttributeHelper
#attribute_enabled?, #option_enabled?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(parent: nil) ⇒ SharedStringTable
Returns a new instance of SharedStringTable.
14 15 16 17 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/shared_string_table.rb', line 14 def initialize(parent: nil) @string_indexes = [] super end |
Instance Attribute Details
#count ⇒ Integer (readonly)
Returns count of shared strings.
8 9 10 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/shared_string_table.rb', line 8 def count @count end |
#string_indexes ⇒ Array<StringIndex> (readonly)
Returns String Index.
12 13 14 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/shared_string_table.rb', line 12 def string_indexes @string_indexes end |
#unique_count ⇒ Integer (readonly)
Returns unique count of shared strings.
10 11 12 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/shared_string_table.rb', line 10 def unique_count @unique_count end |
Instance Method Details
#parse(file) ⇒ SharedStringTable
Parse Shared string table file
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |