Class: TableStructure::CSV::Writer
- Inherits:
-
Object
- Object
- TableStructure::CSV::Writer
- Defined in:
- lib/table_structure/csv/writer.rb
Constant Summary collapse
- BOM =
"\uFEFF"
Instance Method Summary collapse
-
#initialize(schema, bom: false, csv_options: {}, header_omitted: false, header_context: nil) ⇒ Writer
constructor
A new instance of Writer.
- #write(items, to:, bom: @options[:bom], csv_options: @options[:csv_options], header_omitted: @inner_options[:header_omitted], header_context: @inner_options[:header_context], &block) ⇒ Object
Constructor Details
#initialize(schema, bom: false, csv_options: {}, header_omitted: false, header_context: nil) ⇒ Writer
Returns a new instance of Writer.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/table_structure/csv/writer.rb', line 8 def initialize( schema, bom: false, csv_options: {}, header_omitted: false, header_context: nil ) require 'csv' = { bom: bom, csv_options: } = { header_omitted: header_omitted, header_context: header_context } @writer = ::TableStructure::Writer.new(schema, **) end |
Instance Method Details
#write(items, to:, bom: @options[:bom], csv_options: @options[:csv_options], header_omitted: @inner_options[:header_omitted], header_context: @inner_options[:header_context], &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/table_structure/csv/writer.rb', line 29 def write( items, to:, bom: [:bom], csv_options: [:csv_options], header_omitted: [:header_omitted], header_context: [:header_context], &block ) = { header_omitted: header_omitted, header_context: header_context } to << BOM if bom csv = ::CSV.new(to, **) @writer.write(items, to: csv, **, &block) end |