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 }
- COLORS =
storage colors
{ :red=>0, :black=>1 }
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.
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/axlsx/util/storage.rb', line 134 def initialize(name, = {}) @left = @right = @child = -1 @sector = @size = @created = @modified = 0 .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
#child ⇒ Integer
The 0 based index in the directoies chain for the child of this storage.
101 102 103 |
# File 'lib/axlsx/util/storage.rb', line 101 def child @child end |
#color ⇒ Integer
The color of this node in the directory tree. Defaults to black if not specified
43 44 45 |
# File 'lib/axlsx/util/storage.rb', line 43 def color @color end |
#created ⇒ Integer
The created attribute for the storage
105 106 107 |
# File 'lib/axlsx/util/storage.rb', line 105 def created @created end |
#data ⇒ Object
The stream associated with this storage
74 75 76 |
# File 'lib/axlsx/util/storage.rb', line 74 def data @data end |
#left ⇒ Integer
Returns left.
93 94 95 |
# File 'lib/axlsx/util/storage.rb', line 93 def left @left end |
#modified ⇒ Integer
The modified attribute for the storage
109 110 111 |
# File 'lib/axlsx/util/storage.rb', line 109 def modified @modified end |
#name ⇒ Object
the name of the stream
59 60 61 |
# File 'lib/axlsx/util/storage.rb', line 59 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
56 57 58 |
# File 'lib/axlsx/util/storage.rb', line 56 def name_size @name_size end |
#right ⇒ Integer
The 0 based index in the directoies chain for this the right sibling of this storage.
97 98 99 |
# File 'lib/axlsx/util/storage.rb', line 97 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
88 89 90 |
# File 'lib/axlsx/util/storage.rb', line 88 def sector @sector end |
#size ⇒ Object (readonly)
The size of the stream
71 72 73 |
# File 'lib/axlsx/util/storage.rb', line 71 def size @size end |
#type ⇒ Integer
The type of storage see TYPES
114 115 116 |
# File 'lib/axlsx/util/storage.rb', line 114 def type @type end |
Instance Method Details
#to_s ⇒ String
Creates a byte string for this storage
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 |