Hi,
When using the enumerator form of OSV, if you call the #peek method, it moves the current position forward to the next row, so that the "peeked" row is now no longer yielded or returned when iterating the enumerator.
Current behaviour:
irb(main):001> require 'osv'
true
irb(main):002> require 'stringio'
false
irb(main):003> s = StringIO.new("test_1,test_2\r\nfoo,bar\r\n")
#<StringIO:0x000000012498b960>
irb(main):004> e = OSV.for_each(s)
#<Enumerator: OSV:for_each(#<StringIO:0x000000012498b960>, has_headers: true, col_sep: ,, quote_char: ", nil_string: , result_type: hash, flexible: false, trim: , ignore_null_bytes: false, lossy: false)>
irb(main):005> e.peek.keys
[
[0] "test_1",
[1] "test_2"
]
irb(main):006> e.each { |r| puts r['test_1'] }
nil
Expected behaviour:
irb(main):001> require 'osv'
true
irb(main):002> require 'stringio'
false
irb(main):003> s = StringIO.new("test_1,test_2\r\nfoo,bar\r\n")
#<StringIO:0x000000012498b960>
irb(main):004> e = OSV.for_each(s)
#<Enumerator: OSV:for_each(#<StringIO:0x000000012498b960>, has_headers: true, col_sep: ,, quote_char: ", nil_string: , result_type: hash, flexible: false, trim: , ignore_null_bytes: false, lossy: false)>
irb(main):005> e.peek.keys
[
[0] "test_1",
[1] "test_2"
]
irb(main):006> e.each { |r| puts r['test_1'] }
foo
nil
From Ruby documentation for Enumerator#peek
Returns the next object in the enumerator, but doesn’t move the internal position forward.
Hi,
When using the enumerator form of OSV, if you call the
#peekmethod, it moves the current position forward to the next row, so that the "peeked" row is now no longer yielded or returned when iterating the enumerator.Current behaviour:
Expected behaviour:
From Ruby documentation for Enumerator#peek