Sha256: b9e609dad52b173d399fba8fea591edd6be45cdb11cd97a1ccc07c59bf4eed5a

Contents?: true

Size: 942 Bytes

Versions: 15

Compression:

Stored size: 942 Bytes

Contents

module RubyFromExcel
  class Relationships < Hash
  
    attr_reader :shared_strings
  
    def self.for_file(filename)
      root_directory = File.dirname(filename)
      relationships_xml_file = File.join(root_directory,'_rels',"#{File.basename(filename)}.rels")
      return Relationships.new unless File.exist?(relationships_xml_file)
      xml = File.open(relationships_xml_file) { |f| Nokogiri::XML(f) }
      Relationships.new(xml,root_directory)
    end
  
    def initialize(xml = nil, root_directory = nil)
      return unless xml
      xml.css("Relationship").each do |relationship|
        filename = root_directory ? File.expand_path(File.join(root_directory,relationship['Target'])) : relationship['Target']
        self[relationship['Id']] = filename
        @shared_strings = filename if relationship['Type'] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
      end
    end
  
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rubyfromexcel-0.0.23 lib/excelfile/relationships.rb
rubyfromexcel-0.0.22 lib/excelfile/relationships.rb
rubyfromexcel-0.0.21 lib/excelfile/relationships.rb
rubyfromexcel-0.0.20 lib/excelfile/relationships.rb
rubyfromexcel-0.0.19 lib/excelfile/relationships.rb
rubyfromexcel-0.0.18 lib/excelfile/relationships.rb
rubyfromexcel-0.0.17 lib/excelfile/relationships.rb
rubyfromexcel-0.0.16 lib/excelfile/relationships.rb
rubyfromexcel-0.0.13 lib/excelfile/relationships.rb
rubyfromexcel-0.0.10 lib/excelfile/relationships.rb
rubyfromexcel-0.0.9 lib/excelfile/relationships.rb
rubyfromexcel-0.0.7 lib/excelfile/relationships.rb
rubyfromexcel-0.0.6 lib/excelfile/relationships.rb
rubyfromexcel-0.0.5 lib/excelfile/relationships.rb
rubyfromexcel-0.0.4 lib/excelfile/relationships.rb