5
6
7
8
9
10
11
12
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/smarter_csv/headers.rb', line 5
def (filehandle, options)
@raw_header = nil @headers = nil = []
= nil
if options[:headers_in_file] = @raw_header = next_line_with_counts(filehandle, options)
= (, options) unless .nil?
raise SmarterCSV::EmptyFileError, "Empty CSV file" if blank?()
, = parse(, options)
= (, options)
else
unless options[:user_provided_headers]
raise SmarterCSV::IncorrectOption, "ERROR: If :headers_in_file is set to false, you have to provide :user_provided_headers"
end
end
if options[:user_provided_headers]
unless options[:user_provided_headers].is_a?(Array) && !options[:user_provided_headers].empty?
raise(SmarterCSV::IncorrectOption, "ERROR: incorrect format for user_provided_headers! Expecting array with headers.")
end
= options[:user_provided_headers]
if defined?() && !.nil?
if .size !=
raise SmarterCSV::HeaderSizeMismatch, "ERROR: :user_provided_headers defines #{.size} headers != CSV-file has #{} headers"
else
end
end
=
else
=
end
[, .size]
end
|