Class: ReadXls::RecordHandler::Sst

Inherits:
Base
  • Object
show all
Defined in:
lib/read_xls/record_handler/sst.rb

Constant Summary collapse

F_HIGH_BYTE =
0x01
STRING_BEGIN_OFFSET =
3
DATA_OFFSET =
8
STRING_COUNT_OFFSET =
4

Instance Attribute Summary

Attributes inherited from Base

#biff, #builder, #record_data, #record_number

Instance Method Summary collapse

Methods inherited from Base

call, #initialize

Constructor Details

This class inherits a constructor from ReadXls::RecordHandler::Base

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/read_xls/record_handler/sst.rb', line 9

def call
  string_count    = record_data
                      .byteslice(STRING_COUNT_OFFSET, 4)
                      .unpack("V")
                      .first

  string_data     = record_data.byteslice(DATA_OFFSET..-1)
  string_position = 0

  strings = string_count.times.map do |i|
    char_count, grbit = string_data
                          .byteslice(string_position, STRING_BEGIN_OFFSET)
                          .unpack("vC")

    char_byte_size = (grbit & F_HIGH_BYTE) == 0 ? 1 : 2
    string_begin   = string_position + STRING_BEGIN_OFFSET
    string_length  = char_count * char_byte_size

    string_position = string_begin + string_length

    string_data.byteslice(string_begin, string_length)
  end

  builder.sst = ::ReadXls::Workbook::SharedStringTable.new(strings.uniq)
end