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".freeze
TYPES =

storage types

{
  :root => 5,
  :stream => 2,
  :storage => 1
}.freeze
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.

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


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

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.



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

def child
  @child
end

#colorInteger

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



40
41
42
# File 'lib/axlsx/util/storage.rb', line 40

def color
  @color
end

#createdInteger

The created attribute for the storage



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

def created
  @created
end

#dataObject

The stream associated with this storage



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

def data
  @data
end

#leftInteger



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

def left
  @left
end

#modifiedInteger

The modified attribute for the storage



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

def modified
  @modified
end

#nameObject

the name of the stream



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

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



53
54
55
# File 'lib/axlsx/util/storage.rb', line 53

def name_size
  @name_size
end

#rightInteger

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



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

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



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

def sector
  @sector
end

#sizeObject (readonly)

The size of the stream



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

def size
  @size
end

#typeInteger

The type of storage see TYPES



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

def type
  @type
end

Instance Method Details

#to_sString

Creates a byte string for this storage



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

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