lib/axlsx/package.rb in axlsx-1.3.1 vs lib/axlsx/package.rb in axlsx-1.3.2

- old
+ new

@@ -1,12 +1,12 @@ # encoding: UTF-8 module Axlsx # Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid # xlsx document including valdation and serialization. class Package + include Axlsx::OptionsParser - # provides access to the app doc properties for this package # see App attr_reader :app # provides access to the core doc properties for the package @@ -21,13 +21,11 @@ # @example Package.new :author => 'you!', :workbook => Workbook.new def initialize(options={}) @workbook = nil @core, @app = Core.new, App.new @core.creator = options[:author] || @core.creator - options.each do |o| - self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" - end + parse_options options yield self if block_given? end # Shortcut to specify that the workbook should use autowidth # @see Workbook#use_autowidth @@ -173,53 +171,53 @@ # The parts of a package # @return [Array] An array of hashes that define the entry, document and schema for each part of the package. # @private def parts - @parts = [ + parts = [ {:entry => RELS_PN, :doc => relationships.to_xml_string, :schema => RELS_XSD}, {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles.to_xml_string, :schema => SML_XSD}, {:entry => CORE_PN, :doc => @core.to_xml_string, :schema => CORE_XSD}, {:entry => APP_PN, :doc => @app.to_xml_string, :schema => APP_XSD}, {:entry => WORKBOOK_RELS_PN, :doc => workbook.relationships.to_xml_string, :schema => RELS_XSD}, {:entry => CONTENT_TYPES_PN, :doc => content_types.to_xml_string, :schema => CONTENT_TYPES_XSD}, {:entry => WORKBOOK_PN, :doc => workbook.to_xml_string, :schema => SML_XSD} ] workbook.drawings.each do |drawing| - @parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml_string, :schema => RELS_XSD} - @parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml_string, :schema => DRAWING_XSD} + parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml_string, :schema => RELS_XSD} + parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml_string, :schema => DRAWING_XSD} end workbook.tables.each do |table| - @parts << {:entry => "xl/#{table.pn}", :doc => table.to_xml_string, :schema => SML_XSD} + parts << {:entry => "xl/#{table.pn}", :doc => table.to_xml_string, :schema => SML_XSD} end workbook.comments.each do|comment| if comment.size > 0 - @parts << { :entry => "xl/#{comment.pn}", :doc => comment.to_xml_string, :schema => SML_XSD } - @parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing.to_xml_string, :schema => nil } + parts << { :entry => "xl/#{comment.pn}", :doc => comment.to_xml_string, :schema => SML_XSD } + parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing.to_xml_string, :schema => nil } end end workbook.charts.each do |chart| - @parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml_string, :schema => DRAWING_XSD} + parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml_string, :schema => DRAWING_XSD} end workbook.images.each do |image| - @parts << {:entry => "xl/#{image.pn}", :path => image.image_src} + parts << {:entry => "xl/#{image.pn}", :path => image.image_src} end if use_shared_strings - @parts << {:entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings.to_xml_string, :schema => SML_XSD} + parts << {:entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings.to_xml_string, :schema => SML_XSD} end workbook.worksheets.each do |sheet| - @parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml_string, :schema => RELS_XSD} - @parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml_string, :schema => SML_XSD} + parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml_string, :schema => RELS_XSD} + parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml_string, :schema => SML_XSD} end - @parts + parts end # Performs xsd validation for a signle document # # @param [String] schema path to the xsd schema to be used in validation.