Class: BiffRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/surpass/biff_record.rb

Constant Summary collapse

BIFF_LIMIT =

limit for BIFF7/8

0x2020
CONTINUE_RECORD_ID =
0x003C

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBiffRecord

By default, initialize to ”. May be overridden in subclass.



103
104
105
# File 'lib/surpass/biff_record.rb', line 103

def initialize
  @record_data = ''
end

Instance Attribute Details

#record_dataObject

Returns the value of attribute record_data.



96
97
98
# File 'lib/surpass/biff_record.rb', line 96

def record_data
  @record_data
end

Instance Method Details

#record_headerObject



108
109
110
# File 'lib/surpass/biff_record.rb', line 108

def record_header
  [self.class::RECORD_ID, @record_data.length].pack('v2')
end

#to_biffObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/surpass/biff_record.rb', line 112

def to_biff
  if @record_data.length > BIFF_LIMIT
    chunks = []
    pos = 0
    while pos < @record_data.length
      chunk_pos = pos + BIFF_LIMIT
      chunk = @record_data[pos...chunk_pos]
      chunks << chunk
      pos = chunk_pos
    end
    
    continues = [self.class::RECORD_ID, chunks[0].length].pack('v2') + chunks[0]
    chunks.each_with_index do |c, i|
      next if i == 0
      continues += [CONTINUE_RECORD_ID, c.length].pack('v2') + c
    end
    continues
  else
    record_header + @record_data
  end
end