Class: RubyFromExcel::Relationships
- Inherits:
-
Hash
- Object
- Hash
- RubyFromExcel::Relationships
- Defined in:
- lib/excelfile/relationships.rb
Instance Attribute Summary collapse
-
#shared_strings ⇒ Object
readonly
Returns the value of attribute shared_strings.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(xml = nil, root_directory = nil) ⇒ Relationships
constructor
A new instance of Relationships.
Constructor Details
#initialize(xml = nil, root_directory = nil) ⇒ Relationships
Returns a new instance of Relationships.
14 15 16 17 18 19 20 21 |
# File 'lib/excelfile/relationships.rb', line 14 def initialize(xml = nil, root_directory = nil) return unless xml xml.css("Relationship").each do |relationship| filename = root_directory ? File.(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 |
Instance Attribute Details
#shared_strings ⇒ Object (readonly)
Returns the value of attribute shared_strings.
4 5 6 |
# File 'lib/excelfile/relationships.rb', line 4 def shared_strings @shared_strings end |
Class Method Details
.for_file(filename) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/excelfile/relationships.rb', line 6 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 |