Sha256: 996d48f8ff08a2982a24a4ce86ed5eef4d3db833c089b94ae9e91a6fad5b848d

Contents?: true

Size: 835 Bytes

Versions: 5

Compression:

Stored size: 835 Bytes

Contents

require 'roo/excelx/extractor'

module Roo
  class Excelx::SharedStrings < Excelx::Extractor
    def [](index)
      to_a[index]
    end

    def to_a
      @array ||= extract_shared_strings
    end

    private

    def extract_shared_strings
      if doc_exists?
        # read the shared strings xml document
        doc.xpath("/sst/si").map do |si|
          shared_string = ''
          si.children.each do |elem|
            case elem.name
              when 'r'
                elem.children.each do |r_elem|
                  if r_elem.name == 't'
                    shared_string << r_elem.content
                  end
                end
              when 't'
                shared_string = elem.content
            end
          end
          shared_string
        end
      else
        []
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
culturecode-roo-2.0.2 lib/roo/excelx/shared_strings.rb
culturecode-roo-2.0.1 lib/roo/excelx/shared_strings.rb
roo-2.0.0 lib/roo/excelx/shared_strings.rb
roo-2.0.0beta1 lib/roo/excelx/shared_strings.rb
roo-andyw8-2.0.0 lib/roo/excelx/shared_strings.rb