Class: Axlsx::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/doc_props/core.rb

Overview

Note:

Packages manage their own core object.

The core object for the package.

See Also:

  • Package#core

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Core

Creates a new Core object.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • creator (String)


12
13
14
# File 'lib/axlsx/doc_props/core.rb', line 12

def initialize(options={})
  @creator = options[:creator] || 'axlsx'      
end

Instance Attribute Details

#creatorString

The author of the document. By default this is ‘axlsx’

Returns:

  • (String)


8
9
10
# File 'lib/axlsx/doc_props/core.rb', line 8

def creator
  @creator
end

Instance Method Details

#to_xmlString

Serializes the core object. The created dcterms item is set to the current time when this method is called.

Returns:

  • (String)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/axlsx/doc_props/core.rb', line 18

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
end