Module: Fileconv::CSV
- Includes:
- Base
- Defined in:
- lib/fileconv/csv.rb
Instance Method Summary
collapse
Methods included from Base
#conv
Methods included from Convertor
#conv_result, #convert_file, #convert_line, #init_acc, #init_conv, #input_dir, #input_ext, #input_files, #output_dir, #output_filename, #read_file, #result_filename
#post_conv_result, #post_init_acc, #post_init_conv, #post_input_files, #pre_conv_result, #pre_convert_line, #pre_init_acc, #pre_input_files
Instance Method Details
#post_convert_file(rows, acc) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/fileconv/csv.rb', line 30
def post_convert_file(rows, acc)
return unless rows
::CSV.generate("", @opts[:write_csv_opts]) do |csv|
rows.each do |row|
csv << row
end
end
end
|
#post_convert_line(line, acc) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/fileconv/csv.rb', line 18
def post_convert_line(line, acc)
return unless line
if line.is_a? ::CSV::Row
[line]
elsif line[0].is_a? Array
line
else
[line]
end
end
|
#pre_convert_file(data, acc) ⇒ Object
14
15
16
|
# File 'lib/fileconv/csv.rb', line 14
def pre_convert_file(data, acc)
::CSV.parse(data, @opts[:read_csv_opts])
end
|
#pre_init_conv ⇒ Object
8
9
10
11
12
|
# File 'lib/fileconv/csv.rb', line 8
def pre_init_conv
@opts[:line_mode] = true
@opts[:read_csv_opts] ||= {}
@opts[:write_csv_opts] ||= {}
end
|