Class: DBF::RecordIterator
- Inherits:
-
Object
- Object
- DBF::RecordIterator
- Defined in:
- lib/dbf/record_iterator.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(data, context, header_length, record_length, record_count) ⇒ RecordIterator
constructor
A new instance of RecordIterator.
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
#each ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dbf/record_iterator.rb', line 13 def each buf = read_buffer return unless buf # Bound the iteration by the bytes actually read so a crafted # record_count (or record_length == 0) cannot drive an unbounded loop. max_records = @record_length > 0 ? buf.bytesize / @record_length : 0 count = @record_count < max_records ? @record_count : max_records pos = 0 count.times do if buf.getbyte(pos) == 0x2A yield nil else yield Record.new(buf, @context, pos + 1) end pos += @record_length end end |