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