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, DocumentProperties, SharedStringsTable, Stylesheet, Workbook, WorkbookRelationships, Worksheet
Class Method Summary collapse
- .filepath ⇒ Object
-
.parse_file(dirpath) ⇒ Object
Generates the top-level OOXML object by parsing its XML file from the temporary directory containing the unzipped contents of
.xslx
=== Parameters *dirpath
- path to the directory with the unzipped.xslx
contents. -
.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(zipfile) ⇒ Object
Saves the contents of the object as XML to respective location in
.xslx
zip container. -
#filepath ⇒ Object
Prototype method.
Methods included from OOXMLObjectClassMethods
#define_attribute, #define_child_node, #define_element_name, #obtain_class_variable, #parse, #set_countable
Methods included from OOXMLObjectInstanceMethods
#before_write_xml, #dup, #index_in_collection, #initialize, #write_xml
Class Method Details
.filepath ⇒ Object
391 392 393 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 391 def self.filepath raise 'Subclass responsebility' end |
.parse_file(dirpath) ⇒ Object
Generates the top-level OOXML object by parsing its XML file from the temporary directory containing the unzipped contents of .xslx
Parameters
-
dirpath
- path to the directory with the unzipped.xslx
contents.
409 410 411 412 413 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 409 def self.parse_file(dirpath) full_path = File.join(dirpath, filepath) return nil unless File.exist?(full_path) parse(File.open(full_path, 'r')) 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"prefix" => "url"
Examples
set_namespaces('xmlns' => 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
'xmlns:r' => 'http://schemas.openxmlformats.org/officeDocument/2006/relationships')
401 402 403 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 401 def self.set_namespaces(namespace_hash) self.class_variable_set(:@@ooxml_namespaces, namespace_hash) end |
Instance Method Details
#add_to_zip(zipfile) ⇒ 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.
418 419 420 421 422 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 418 def add_to_zip(zipfile) xml_string = write_xml return if xml_string.empty? zipfile.get_output_stream(self.filepath) { |f| f << xml_string } end |
#filepath ⇒ Object
Prototype method. For top-level OOXML object, returns the path at which the current object’s XML file is located within the .xslx
zip container.
387 388 389 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 387 def filepath self.class.filepath end |