Class: TableStructure::CSV::Writer
- Inherits:
-
Object
- Object
- TableStructure::CSV::Writer
- Defined in:
- lib/table_structure/csv/writer.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ bom: false, csv_options: {} }.freeze
- INNER_WRITER_DEFAULT_OPTIONS =
::TableStructure::Writer::DEFAULT_OPTIONS
- INNER_WRITER_IGNORED_OPTION_KEYS =
i[ result_type method ].freeze
- BOM =
"\uFEFF"
Instance Method Summary collapse
-
#initialize(schema, **options) ⇒ Writer
constructor
A new instance of Writer.
- #write(items, to:, **options, &block) ⇒ Object
Constructor Details
#initialize(schema, **options) ⇒ Writer
Returns a new instance of Writer.
19 20 21 22 23 24 |
# File 'lib/table_structure/csv/writer.rb', line 19 def initialize(schema, **) require 'csv' = DEFAULT_OPTIONS.merge(()) = () @writer = ::TableStructure::Writer.new(schema, **) end |
Instance Method Details
#write(items, to:, **options, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/table_structure/csv/writer.rb', line 26 def write(items, to:, **, &block) = .merge(()) = () if [:bom] to.send(INNER_WRITER_DEFAULT_OPTIONS[:method], BOM) end csv = ::CSV.new(to, **[:csv_options]) @writer.write(items, to: csv, **, &block) end |