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
15
# 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)
    warn "[TableStructure] Pass Writer as an argument has been deprecated. Pass Schema instead. #{caller_locations(1, 1)}"
    @writer = schema_or_writer
  else
    raise ::TableStructure::Error, "Must be either Schema or Writer. #{schema_or_writer}"
  end
end

Instance Method Details

#iterate(items, **options, &block) ⇒ Object



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

def iterate(items, **options, &block)
  # TODO: Change not to use Writer.
  Enumerator.new { |y| @writer.write(items, to: y, **options, &block) }
end