Class: RubyXL::WorkbookRoot

Inherits:
Object
  • Object
show all
Includes:
RelationshipSupport
Defined in:
lib/rubyXL/objects/root.rb

Constant Summary collapse

@@debug =
nil

Instance Attribute Summary collapse

Attributes included from RelationshipSupport

#generic_storage, #relationship_container

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RelationshipSupport

#attach_relationship, #collect_related_objects, included, #load_relationships, #store_relationship

Instance Attribute Details

#content_typesObject

Returns the value of attribute content_types.



14
15
16
# File 'lib/rubyXL/objects/root.rb', line 14

def content_types
  @content_types
end

#core_propertiesObject

Returns the value of attribute core_properties.



13
14
15
# File 'lib/rubyXL/objects/root.rb', line 13

def core_properties
  @core_properties
end

#custom_propertiesObject

Returns the value of attribute custom_properties.



13
14
15
# File 'lib/rubyXL/objects/root.rb', line 13

def custom_properties
  @custom_properties
end

#document_propertiesObject

Returns the value of attribute document_properties.



13
14
15
# File 'lib/rubyXL/objects/root.rb', line 13

def document_properties
  @document_properties
end

#filepathObject

Returns the value of attribute filepath.



12
13
14
# File 'lib/rubyXL/objects/root.rb', line 12

def filepath
  @filepath
end

#rels_hashObject

Returns the value of attribute rels_hash.



14
15
16
# File 'lib/rubyXL/objects/root.rb', line 14

def rels_hash
  @rels_hash
end

#thumbnailObject

Returns the value of attribute thumbnail.



13
14
15
# File 'lib/rubyXL/objects/root.rb', line 13

def thumbnail
  @thumbnail
end

#workbookObject

Returns the value of attribute workbook.



13
14
15
# File 'lib/rubyXL/objects/root.rb', line 13

def workbook
  @workbook
end

Class Method Details

.defaultObject



28
29
30
31
32
33
34
35
# File 'lib/rubyXL/objects/root.rb', line 28

def self.default
  obj = self.new
  obj.document_properties    = RubyXL::DocumentPropertiesFile.new
  obj.core_properties        = RubyXL::CorePropertiesFile.new
  obj.relationship_container = RubyXL::OOXMLRelationshipsFile.new
  obj.content_types          = RubyXL::ContentTypes.new
  obj
end

.parse_file(xl_file_path, opts) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rubyXL/objects/root.rb', line 64

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, OOXMLTopLevelObject::ROOT)
      root.workbook.root = root
      root
    }
  rescue ::Zip::Error => e
    raise e, "XLSX file format error: #{e}", e.backtrace
  end
end

Instance Method Details



24
25
26
# File 'lib/rubyXL/objects/root.rb', line 24

def related_objects
  [ content_types, thumbnail, core_properties, document_properties, custom_properties, workbook ]
end

#streamObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rubyXL/objects/root.rb', line 37

def stream
  stream = Zip::OutputStream.write_buffer { |zipstream|
    self.rels_hash = {}
    self.relationship_container.owner = self
    collect_related_objects.compact.each { |obj|
      puts "<-- DEBUG: adding relationship to #{obj.class}" if @@debug
      obj.root = self if obj.respond_to?(:root=)
      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|
        puts "<-- DEBUG:   > #{obj.xlsx_path}" if @@debug
        obj.add_to_zip(zipstream)
      }
    }
  }
  stream.rewind
  stream
end

#xlsx_pathObject



60
61
62
# File 'lib/rubyXL/objects/root.rb', line 60

def xlsx_path
  OOXMLTopLevelObject::ROOT
end