Class: TableStructure::Table::Iterator

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

Instance Method Summary collapse

Constructor Details

#initialize(table, header: { context: nil }) ⇒ Iterator

Returns a new instance of Iterator.



5
6
7
8
# File 'lib/table_structure/table/iterator.rb', line 5

def initialize(table, header: { context: nil })
  @table = table
  @header_options = header
end

Instance Method Details

#iterate(items) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/table_structure/table/iterator.rb', line 10

def iterate(items)
  ::Enumerator.new do |y|
    if @header_options
      header_context = @header_options.is_a?(Hash) ? @header_options[:context] : nil
      y << @table.header(context: header_context)
    end
    @table
      .body(items)
      .each { |row| y << row }
  end
end