Method: ActiveImport::ImportExcel#all_headers_found

Defined in:
lib/active_import/import_excel.rb

#all_headers_found(headers) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_import/import_excel.rb', line 13

def all_headers_found(headers)
  mappings = @converter.columns

  @missing_headers_mandatory = []
  @missing_headers_optional = []
  found_at_least_one = false

  mappings.each_pair do |column_name, mapping|
    if headers[column_name].nil?
      if mapping[:mandatory]
        @missing_headers_mandatory << column_name
      else
        @missing_headers_optional << column_name
      end
    else
      found_at_least_one = true
    end
  end
  if found_at_least_one
    @missing_headers_optional.each { |field| puts "Missing optional column #{field.to_s.yellow}" }
    @missing_headers_mandatory.each { |field| puts "Missing mandatory column #{field.to_s.red}" }
  end
  return false unless @missing_headers_mandatory.empty?
  true
end