Class: Axlsx::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/util/storage.rb

Overview

The Storage class represents a storage object or stream in a compound file.

Constant Summary collapse

PACKING =

Packing for the Storage when pushing an array of items into a byte stream Name, name length, type, color, left sibling, right sibling, child, classid, state, created, modified, sector, size

"s32 s1 c2 l3 x16 x4 q2 l q"
TYPES =

storage types

{
  :root=>5,
  :stream=>2,
  :storage=>1
}
COLORS =

storage colors

{
  :red=>0, 
  :black=>1
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Storage

Creates a new storage object.

Parameters:

  • name (String)

    the name of the storage

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

    a customizable set of options

Options Hash (options):

  • color (Integer)

    @default black

  • type (Integer)

    @default storage

  • data (String)
  • left (Integer)

    @default -1

  • right (Integer)

    @default -1

  • child (Integer)

    @default -1

  • created (Integer)

    @default 0

  • modified (Integer)

    @default 0

  • sector (Integer)

    @default 0



134
135
136
137
138
139
140
141
142
143
# File 'lib/axlsx/util/storage.rb', line 134

def initialize(name, options= {})
  @left = @right = @child = -1
  @sector = @size = @created = @modified = 0
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
  @color ||= COLORS[:black]
  @type ||= (data.nil? ? TYPES[:storage] : TYPES[:stream])
  self.name = name
end

Instance Attribute Details

#childInteger

The 0 based index in the directoies chain for the child of this storage.

Returns:

  • (Integer)

    child



101
102
103
# File 'lib/axlsx/util/storage.rb', line 101

def child
  @child
end

#colorInteger

The color of this node in the directory tree. Defaults to black if not specified

Returns:

  • (Integer)

    color



43
44
45
# File 'lib/axlsx/util/storage.rb', line 43

def color
  @color
end

#createdInteger

The created attribute for the storage

Returns:

  • (Integer)

    created



105
106
107
# File 'lib/axlsx/util/storage.rb', line 105

def created
  @created
end

#dataObject

The stream associated with this storage



74
75
76
# File 'lib/axlsx/util/storage.rb', line 74

def data
  @data
end

#leftInteger

Returns left.

Returns:

  • (Integer)

    left



93
94
95
# File 'lib/axlsx/util/storage.rb', line 93

def left
  @left
end

#modifiedInteger

The modified attribute for the storage

Returns:

  • (Integer)

    modified



109
110
111
# File 'lib/axlsx/util/storage.rb', line 109

def modified
  @modified
end

#nameObject

the name of the stream



59
60
61
# File 'lib/axlsx/util/storage.rb', line 59

def name
  @name
end

#name_sizeInteger (readonly)

The size of the name for this node. interesting to see that office actually uses ‘R’ for the root directory and lists the size as 2 bytes - thus is it NOT null terminated. I am making this r/w so that I can override the size

Returns:

  • (Integer)

    color



56
57
58
# File 'lib/axlsx/util/storage.rb', line 56

def name_size
  @name_size
end

#rightInteger

The 0 based index in the directoies chain for this the right sibling of this storage.

Returns:

  • (Integer)

    right



97
98
99
# File 'lib/axlsx/util/storage.rb', line 97

def right
  @right
end

#sectorInteger

The starting sector for the stream. If this storage is not a stream, or the root node this is nil

Returns:

  • (Integer)

    sector



88
89
90
# File 'lib/axlsx/util/storage.rb', line 88

def sector
  @sector
end

#sizeObject (readonly)

The size of the stream



71
72
73
# File 'lib/axlsx/util/storage.rb', line 71

def size
  @size
end

#typeInteger

The type of storage see TYPES

Returns:

  • (Integer)

    type



114
115
116
# File 'lib/axlsx/util/storage.rb', line 114

def type
  @type
end

Instance Method Details

#to_sString

Creates a byte string for this storage

Returns:

  • (String)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/axlsx/util/storage.rb', line 20

def to_s
 data = [@name.concat(Array.new(32-@name.size, 0)), 
         @name_size, 
         @type, 
         @color, 
         @left, 
         @right, 
         @child, 
         @created,
         @modified, 
         @sector, 
         @size].flatten
  data.pack(PACKING)
end