Module: DS::CSVUtil::ClassMethods

Included in:
DS::CSVUtil
Defined in:
lib/ds/csv_util.rb

Constant Summary collapse

NESTED_COLUMNS =

TODO: These methods don’t belong in CSVUtil; find them a new home TODO: Remove CSVUtil when the above TODO is complete Columns with two levels of subfields, separated by ‘|’ and ‘;’

%w{ subject subject_label genre genre_label production_place production_place_label language language_label }
PIPE_SPLIT_REGEXP =

split on pipes that are not escaped with ‘\’

%r{(?<!\\)\|}
PIPE_SEMICOLON_REGEXP =

split on pipes and semicolons that are not escaped with ‘\’

%r{(?<!\\)[;|]}

Instance Method Summary collapse

Instance Method Details

#row_valid?(row, index) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/ds/csv_util.rb', line 31

def row_valid? row, index
  valid       = true
  DS::Util::CsvValidator.validate_whitespace(row, row_num: index, nested_columns: NESTED_COLUMNS).each do |error|
    valid = false
    STDERR.puts "WARNING: #{error}"
  end
  valid
end

#validate(rows) ⇒ Boolean

Check all rows for validation errors, including:

- trailing spaces in values

Parameters:

  • rows (Array<Hash>)

    the CSV rows

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/ds/csv_util.rb', line 17

def validate rows
  valid = true
  rows.each_with_index do |row,index|
    valid = false unless row_valid? row, index
  end
  valid
end