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, header_omitted: false, header_context: nil }.freeze
- FIXED_OPTIONS =
{ result_type: :array, 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 |
# File 'lib/table_structure/csv/writer.rb', line 19 def initialize(schema, **) require 'csv' @options = DEFAULT_OPTIONS.merge().merge(FIXED_OPTIONS) @writer = ::TableStructure::Writer.new(schema, **@options) end |
Instance Method Details
#write(items, to:, **options, &block) ⇒ Object
25 26 27 28 29 |
# File 'lib/table_structure/csv/writer.rb', line 25 def write(items, to:, **, &block) = @options.merge().merge(FIXED_OPTIONS) to.send([:method], BOM) if [:bom] @writer.write(items, to: ::CSV.new(to), **, &block) end |