Sha256: 97cc494f5501a89e0c132a9b0c1672f2ca7a5ce4925d08c2b53dd1b4ffc1541f

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

# encoding: UTF-8
module Axlsx
  # The core object for the package.
  # @note Packages manage their own core object.
  # @see Package#core
  class Core
    # The author of the document. By default this is 'axlsx'
    # @return [String]
    attr_accessor :creator
    
    # Creates a new Core object.
    # @option options [String] creator
    def initialize(options={})
      @creator = options[:creator] || 'axlsx'      
    end

    # Serializes the core object. The created dcterms item is set to the current time when this method is called.
    # @return [String]
    def to_xml()
      builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
        xml.send('cp:coreProperties', 
                 :"xmlns:cp" => CORE_NS, 
                 :'xmlns:dc' => CORE_NS_DC, 
                 :'xmlns:dcmitype'=>CORE_NS_DCMIT, 
                 :'xmlns:dcterms'=>CORE_NS_DCT, 
                 :'xmlns:xsi'=>CORE_NS_XSI) {
          xml['dc'].creator self.creator
          xml['dcterms'].created Time.now.strftime('%Y-%m-%dT%H:%M:%S'), :'xsi:type'=>"dcterms:W3CDTF"
          xml['cp'].revision 0
        }
      end  
      builder.to_xml(:save_with => 0)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
axlsx-1.0.18 lib/axlsx/doc_props/core.rb
axlsx-1.0.17 lib/axlsx/doc_props/core.rb