-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer.rb
41 lines (35 loc) · 779 Bytes
/
writer.rb
1
2
3
4
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
# frozen_string_literal: true
module TableStructure
module CSV
class Writer
BOM = "\uFEFF"
def initialize(
schema,
bom: false,
csv_options: {},
header: { context: nil, step: nil }
)
require 'csv'
@options = {
bom: bom,
csv_options: csv_options
}
inner_options = {
header: header
}
@writer = ::TableStructure::Writer.new(schema, **inner_options)
end
def write(
items,
to:,
bom: @options[:bom],
csv_options: @options[:csv_options],
&block
)
to << BOM if bom
csv = ::CSV.new(to, **csv_options)
@writer.write(items, to: csv, &block)
end
end
end
end