Class: TableStructure::Iterator

Inherits:
Object
  • Object
show all
Defined in:
lib/table_structure/iterator.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema_or_writer, **options) ⇒ Iterator

Returns a new instance of Iterator.



5
6
7
8
9
10
11
12
13
14
# File 'lib/table_structure/iterator.rb', line 5

def initialize(schema_or_writer, **options)
  if schema_or_writer.is_a?(Schema)
    schema = schema_or_writer
    @writer = Writer.new(schema, options)
  elsif schema_or_writer.is_a?(Writer)
    @writer = schema_or_writer
  else
    raise ::TableStructure::Error, 'First argument must be either Schema or Writer.'
  end
end

Instance Method Details

#iterate(items, **options) ⇒ Object



16
17
18
# File 'lib/table_structure/iterator.rb', line 16

def iterate(items, **options)
  Enumerator.new { |y| @writer.write(items, to: y, **options) }
end