Class: RubyXL::OOXMLTopLevelObject
- Inherits:
-
OOXMLObject
- Object
- OOXMLObject
- RubyXL::OOXMLTopLevelObject
- Defined in:
- lib/rubyXL/objects/ooxml_object.rb
Overview
Extension class providing functionality for top-level OOXML objects that are represented by their own .xml
files in .xslx
zip container.
Direct Known Subclasses
CalculationChain, Chartsheet, CommentsFile, Connections, ContentTypes, CorePropertiesFile, DocumentPropertiesFile, ExternalLinksFile, OOXMLRelationshipsFile, QueryTable, SharedStringsTable, Stylesheet, Theme, Workbook, Worksheet
Constant Summary collapse
- SAVE_ORDER =
500
- ROOT =
::Pathname.new('/')
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
Attributes included from OOXMLObjectInstanceMethods
Class Method Summary collapse
-
.parse_file(zip_file, file_path) ⇒ Object
Generates the top-level OOXML object by parsing its XML file from the contents of the
.xslx
container. -
.set_namespaces(namespace_hash) ⇒ Object
Sets the list of namespaces on this object to be added when writing out XML.
Instance Method Summary collapse
-
#add_to_zip(zip_stream) ⇒ Object
Saves the contents of the object as XML to respective location in
.xslx
zip container. - #file_index ⇒ Object
-
#xlsx_path ⇒ Object
Prototype method.
Methods included from OOXMLObjectInstanceMethods
#==, #before_write_xml, included, #index_in_collection, #initialize, #write_xml
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
426 427 428 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 426 def root @root end |
Class Method Details
.parse_file(zip_file, file_path) ⇒ Object
Generates the top-level OOXML object by parsing its XML file from the contents of the .xslx
container.
Parameters
-
zip_file
-.xslx
file asZip::File
object -
file_path
- path to the subject file inside the.xslx
zip archive
448 449 450 451 452 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 448 def self.parse_file(zip_file, file_path) entry = zip_file.find_entry(RubyXL::from_root(file_path)) # Accomodate for Nokogiri Java implementation which is incapable of reading from a stream entry && (entry.get_input_stream { |f| parse(defined?(JRUBY_VERSION) ? f.read : f) }) end |
.set_namespaces(namespace_hash) ⇒ Object
Sets the list of namespaces on this object to be added when writing out XML. Valid only on top-level objects.
Parameters
-
namespace_hash
- Hash of namespaces in the form of"url" => "prefix"
Examples
set_namespaces('http://schemas.openxmlformats.org/spreadsheetml/2006/main' => nil,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships' => 'r')
440 441 442 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 440 def self.set_namespaces(namespace_hash) self.class_variable_set(:@@ooxml_namespaces, namespace_hash) end |
Instance Method Details
#add_to_zip(zip_stream) ⇒ Object
Saves the contents of the object as XML to respective location in .xslx
zip container.
Parameters
-
zipfile
- ::Zip::File to which the resulting XNMML should be added.
457 458 459 460 461 462 463 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 457 def add_to_zip(zip_stream) xml_string = write_xml return false if xml_string.empty? zip_stream.put_next_entry(RubyXL::from_root(self.xlsx_path)) zip_stream.write(xml_string) true end |
#file_index ⇒ Object
465 466 467 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 465 def file_index root.rels_hash[self.class].index{ |f| f.equal?(self) }.to_i + 1 end |
#xlsx_path ⇒ Object
Prototype method. For top-level OOXML object, returns the path at which the current object’s XML file is located within the .xlsx
zip container.
430 431 432 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 430 def xlsx_path raise 'Subclass responsebility' end |