Class: Antz::Source::CsvFile
- Inherits:
-
Object
- Object
- Antz::Source::CsvFile
- Defined in:
- lib/antz/source/csv_file.rb
Instance Method Summary collapse
- #each_row(batch_size:) {|rows| ... } ⇒ Object
-
#initialize(file_path:) ⇒ CsvFile
constructor
A new instance of CsvFile.
Constructor Details
#initialize(file_path:) ⇒ CsvFile
Returns a new instance of CsvFile.
6 7 8 |
# File 'lib/antz/source/csv_file.rb', line 6 def initialize(file_path:) @file_path = file_path end |
Instance Method Details
#each_row(batch_size:) {|rows| ... } ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/antz/source/csv_file.rb', line 10 def each_row(batch_size:) rows = [] CSV.foreach(@file_path, headers: true) do |row| rows << row.to_h if rows.size >= batch_size yield rows rows = [] end end yield rows unless rows.empty? end |