Module: TrajectPlus::Macros::Csv

Defined in:
lib/traject_plus/macros/csv.rb

Overview

Macros for extracting values from CSV rows

Instance Method Summary collapse

Instance Method Details

#column(header_or_index, options = {}) ⇒ Object

Retrieve the value of the column with the given header or index.

Parameters:

  • header_or_index (String)

    the field header or index to accumulate



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/traject_plus/macros/csv.rb', line 9

def column(header_or_index, options = {})
  lambda do |row, accumulator, _context|
    return if row[header_or_index].to_s.empty?
    result = Array(row[header_or_index].to_s)
    unless options.empty?
      Deprecation.warn(self, "passing options to column is deprecated and will be removed in the next major release. Use the Traject 3 pipeline instead")
    end
    result = TrajectPlus::Extraction.apply_extraction_options(result, options)
    accumulator.concat(result)
  end
end