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
}.freeze
COLORS =

storage colors

{
  red: 0,
  black: 1
}.freeze

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


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

def initialize(name, options = {})
  @left = @right = @child = -1
  @sector = @size = @created = @modified = 0
  options.each do |o|
    send("#{o[0]}=", o[1]) if 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



99
100
101
# File 'lib/axlsx/util/storage.rb', line 99

def child
  @child
end

#colorInteger

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

Returns:

  • (Integer)

    color



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

def color
  @color
end

#createdInteger

The created attribute for the storage

Returns:

  • (Integer)

    created



103
104
105
# File 'lib/axlsx/util/storage.rb', line 103

def created
  @created
end

#dataObject

The stream associated with this storage



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

def data
  @data
end

#leftInteger

Returns left.

Returns:

  • (Integer)

    left



91
92
93
# File 'lib/axlsx/util/storage.rb', line 91

def left
  @left
end

#modifiedInteger

The modified attribute for the storage

Returns:

  • (Integer)

    modified



107
108
109
# File 'lib/axlsx/util/storage.rb', line 107

def modified
  @modified
end

#nameObject

the name of the stream



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

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



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

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



95
96
97
# File 'lib/axlsx/util/storage.rb', line 95

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



86
87
88
# File 'lib/axlsx/util/storage.rb', line 86

def sector
  @sector
end

#sizeObject (readonly)

The size of the stream



69
70
71
# File 'lib/axlsx/util/storage.rb', line 69

def size
  @size
end

#typeInteger

The type of storage see TYPES

Returns:

  • (Integer)

    type



112
113
114
# File 'lib/axlsx/util/storage.rb', line 112

def type
  @type
end

Instance Method Details

#to_sString

Creates a byte string for this storage

Returns:

  • (String)


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

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