Class: TableStructure::Writer
- Inherits:
-
Object
- Object
- TableStructure::Writer
- Defined in:
- lib/table_structure/writer.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ header_omitted: false, header_context: nil, method: :<< }
Instance Method Summary collapse
-
#initialize(schema, **options) ⇒ Writer
constructor
A new instance of Writer.
- #write(items, to:, **options) ⇒ Object
Constructor Details
#initialize(schema, **options) ⇒ Writer
Returns a new instance of Writer.
10 11 12 13 |
# File 'lib/table_structure/writer.rb', line 10 def initialize(schema, **) @schema = schema @options = DEFAULT_OPTIONS.merge() end |
Instance Method Details
#write(items, to:, **options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/table_structure/writer.rb', line 15 def write(items, to:, **) = @options.merge() unless [:header_omitted] header = @schema.header(context: [:header_context]) header = yield header if block_given? to.send([:method], header) end to_enum(items).each do |item| row = @schema.row(context: item) row = yield row if block_given? to.send([:method], row) end return end |