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, result_type: nil, # TODO: :array method: :<< }.freeze
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.
12 13 14 15 |
# File 'lib/table_structure/writer.rb', line 12 def initialize(schema, **) @schema = schema = DEFAULT_OPTIONS.merge() end |
Instance Method Details
#write(items, to:, **options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/table_structure/writer.rb', line 17 def write(items, to:, **) = .merge() unless [:header_omitted] header = @schema.header( context: [:header_context], result_type: [:result_type] ) header = yield header if block_given? to.send([:method], header) end enumerize(items).each do |item| row = @schema.row( context: item, result_type: [:result_type] ) row = yield row if block_given? to.send([:method], row) end nil end |