Class: Chronicle::ETL::CSVLoader
Instance Attribute Summary
#connector_registration
Instance Method Summary
collapse
#create_stdout_temp_file, #output_to_stdout?, #write_to_stdout, #write_to_stdout_from_temp_file
Methods inherited from Loader
#initialize, #start
#register_connector
#force_utf8
included
Instance Method Details
#finish ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/chronicle/etl/loaders/csv_loader.rb', line 28
def finish
return unless records.any?
= (records)
csv_options = {}
if @config.
csv_options[:write_headers] = @config.
csv_options[:headers] =
end
csv_output = CSV.generate(**csv_options) do |csv|
records.each do |record|
csv << Chronicle::Utils::HashUtils.flatten_hash(record.to_h)
.values_at(*)
.map { |value| force_utf8(value) }
end
end
if output_to_stdout?
write_to_stdout(csv_output)
else
File.write(@config.output, csv_output)
end
end
|
#load(record) ⇒ Object
24
25
26
|
# File 'lib/chronicle/etl/loaders/csv_loader.rb', line 24
def load(record)
records << record
end
|
#records ⇒ Object
20
21
22
|
# File 'lib/chronicle/etl/loaders/csv_loader.rb', line 20
def records
@records ||= []
end
|