Class: GeoipRedis::CSVReader
- Inherits:
-
Object
- Object
- GeoipRedis::CSVReader
- Defined in:
- lib/geoip_redis/csv_reader.rb
Instance Method Summary collapse
Instance Method Details
#read_by_batch(io, batch_size: 1000, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/geoip_redis/csv_reader.rb', line 9 def read_by_batch(io, batch_size: 1000, &block) batch = [] CSV.new(io).each.lazy.drop(HEADER).each_with_index do |row, idx| batch << row if (idx + 1) % batch_size == 0 block.call(batch) batch = [] end end block.call(batch) unless batch.empty? end |