Class: DBF::RecordIterator

Inherits:
Object
  • Object
show all
Defined in:
lib/dbf/record_iterator.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, context, header_length, record_length, record_count) ⇒ RecordIterator

Returns a new instance of RecordIterator.



5
6
7
8
9
10
11
# File 'lib/dbf/record_iterator.rb', line 5

def initialize(data, context, header_length, record_length, record_count)
  @data = data
  @context = context
  @header_length = header_length
  @record_length = record_length
  @record_count = record_count
end

Instance Method Details

#eachObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dbf/record_iterator.rb', line 13

def each
  buf = read_buffer
  return unless buf

  pos = 0
  @record_count.times do
    if buf.getbyte(pos) == 0x2A
      yield nil
    else
      yield Record.new(buf, @context, pos + 1)
    end
    pos += @record_length
  end
end