Class: Axlsx::Storage
- Inherits:
-
Object
- Object
- Axlsx::Storage
- 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
-
#child ⇒ Integer
The 0 based index in the directoies chain for the child of this storage.
-
#color ⇒ Integer
The color of this node in the directory tree.
-
#created ⇒ Integer
The created attribute for the storage.
-
#data ⇒ Object
The stream associated with this storage.
-
#left ⇒ Integer
Left.
-
#modified ⇒ Integer
The modified attribute for the storage.
-
#name ⇒ Object
the name of the stream.
-
#name_size ⇒ Integer
readonly
The size of the name for this node.
-
#right ⇒ Integer
The 0 based index in the directoies chain for this the right sibling of this storage.
-
#sector ⇒ Integer
The starting sector for the stream.
-
#size ⇒ Object
readonly
The size of the stream.
-
#type ⇒ Integer
The type of storage see TYPES.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Storage
constructor
Creates a new storage object.
-
#to_s ⇒ String
Creates a byte string for this storage.
Constructor Details
#initialize(name, options = {}) ⇒ Storage
Creates a new storage object.
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/axlsx/util/storage.rb', line 132 def initialize(name, = {}) @left = @right = @child = -1 @sector = @size = @created = @modified = 0 .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
#child ⇒ Integer
The 0 based index in the directoies chain for the child of this storage.
99 100 101 |
# File 'lib/axlsx/util/storage.rb', line 99 def child @child end |
#color ⇒ Integer
The color of this node in the directory tree. Defaults to black if not specified
42 43 44 |
# File 'lib/axlsx/util/storage.rb', line 42 def color @color end |
#created ⇒ Integer
The created attribute for the storage
103 104 105 |
# File 'lib/axlsx/util/storage.rb', line 103 def created @created end |
#data ⇒ Object
The stream associated with this storage
72 73 74 |
# File 'lib/axlsx/util/storage.rb', line 72 def data @data end |
#left ⇒ Integer
Returns left.
91 92 93 |
# File 'lib/axlsx/util/storage.rb', line 91 def left @left end |
#modified ⇒ Integer
The modified attribute for the storage
107 108 109 |
# File 'lib/axlsx/util/storage.rb', line 107 def modified @modified end |
#name ⇒ Object
the name of the stream
58 59 60 |
# File 'lib/axlsx/util/storage.rb', line 58 def name @name end |
#name_size ⇒ Integer (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
55 56 57 |
# File 'lib/axlsx/util/storage.rb', line 55 def name_size @name_size end |
#right ⇒ Integer
The 0 based index in the directoies chain for this the right sibling of this storage.
95 96 97 |
# File 'lib/axlsx/util/storage.rb', line 95 def right @right end |
#sector ⇒ Integer
The starting sector for the stream. If this storage is not a stream, or the root node this is nil
86 87 88 |
# File 'lib/axlsx/util/storage.rb', line 86 def sector @sector end |
#size ⇒ Object (readonly)
The size of the stream
69 70 71 |
# File 'lib/axlsx/util/storage.rb', line 69 def size @size end |
#type ⇒ Integer
The type of storage see TYPES
112 113 114 |
# File 'lib/axlsx/util/storage.rb', line 112 def type @type end |
Instance Method Details
#to_s ⇒ String
Creates a byte string for this storage
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 |