class RubyXL::WorkbookRoot

Constants

REL_CLASS

Attributes

content_types[RW]
core_properties[RW]
custom_properties[RW]
document_properties[RW]
filepath[RW]
rels_hash[RW]
thumbnail[RW]
workbook[RW]

Public Class Methods

default() click to toggle source
# File lib/rubyXL/objects/root.rb, line 38
def self.default
  obj = self.new
  obj.document_properties    = RubyXL::DocumentPropertiesFile.new
  obj.core_properties        = RubyXL::CorePropertiesFile.new
  obj.relationship_container = RubyXL::RootRelationships.new
  obj.content_types          = RubyXL::ContentTypes.new
  obj
end
parse_file(xl_file_path, opts) click to toggle source
# File lib/rubyXL/objects/root.rb, line 73
def self.parse_file(xl_file_path, opts)
  begin
    ::Zip::File.open(xl_file_path) { |zip_file|
      root = self.new
      root.filepath = xl_file_path
      root.content_types = RubyXL::ContentTypes.parse_file(zip_file)
      root.load_relationships(zip_file)
      root.workbook.root = root
      root
    }
  rescue ::Zip::Error => e
    raise e, "XLSX file format error: #{e}", e.backtrace
  end
end

Public Instance Methods

attach_relationship(rid, rf) click to toggle source

define_relationship(RubyXL::ThumbnailFile, :thumbnail) define_relationship(RubyXL::CorePropertiesFile, :core_properties) define_relationship(RubyXL::DocumentPropertiesFile, :document_properties) define_relationship(RubyXL::CustomPropertiesFile, :custom_properties) define_relationship(RubyXL::Workbook, :workbook)

# File lib/rubyXL/objects/root.rb, line 27
def attach_relationship(rid, rf)
  case rf
  when RubyXL::ThumbnailFile          then self.thumbnail = rf
  when RubyXL::CorePropertiesFile     then self.core_properties = rf
  when RubyXL::DocumentPropertiesFile then self.document_properties = rf
  when RubyXL::CustomPropertiesFile   then self.custom_properties = rf
  when RubyXL::Workbook               then self.workbook = rf
  else store_relationship(rf, :unknown)
  end
end
stream() click to toggle source
# File lib/rubyXL/objects/root.rb, line 47
def stream
  stream = Zip::OutputStream.write_buffer { |zipstream|
    self.rels_hash = {}
    self.relationship_container.owner = self
    self.content_types.overrides = []
    self.content_types.owner = self
    collect_related_objects.compact.each { |obj|
      puts "<-- DEBUG: adding relationship to #{obj.class}" if @@debug
      self.rels_hash[obj.class] ||= []
      self.rels_hash[obj.class] << obj
    }

    self.rels_hash.keys.sort_by{ |c| c.save_order }.each { |klass|
      puts "<-- DEBUG: saving related #{klass} files" if @@debug
      self.rels_hash[klass].each { |obj|
        obj.workbook = workbook if obj.respond_to?(:workbook=)
        puts "<-- DEBUG:   > #{obj.xlsx_path}" if @@debug
        self.content_types.add_override(obj)
        obj.add_to_zip(zipstream)
      }
    }
  }
  stream.rewind
  stream
end