Method: Csvlint::Validator#validate_header

Defined in:
lib/csvlint/validate.rb

#validate_header(header) ⇒ Object



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/csvlint/validate.rb', line 375

def validate_header(header)
  names = Set.new
  header.map { |h| h.strip! } if @dialect["trim"] == :true
  header.each_with_index do |name, i|
    build_warnings(:empty_column_name, :schema, nil, i + 1) if name == ""
    if names.include?(name)
      build_warnings(:duplicate_column_name, :schema, nil, i + 1)
    else
      names << name
    end
  end
  if @schema
    @schema.validate_header(header, @source, @validate)
    @errors += @schema.errors
    @warnings += @schema.warnings
  end
  valid?
end