Class: Roo::Base

Inherits:
Object show all
Defined in:
lib/libis/tools/extend/roo.rb

Instance Method Summary collapse

Instance Method Details

#each(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/libis/tools/extend/roo.rb', line 10

def each(options = {})
  return to_enum(:each, options) unless block_given?

  if options.empty?
    1.upto(last_row) do |line|
      yield row(line)
    end
  else
    clean_sheet_if_need(options)
    search_or_set_header(options)
    headers = @headers ||
        Hash[(first_column..last_column).map do |col|
          [cell(@header_line, col), col]
        end]

    start_line = @header_line || 1
    start_line = (@header_line || 0) + 1 if @options[:skip_headers]
    start_line.upto(last_row) do |line|
      yield(Hash[headers.map { |k, v| [k, cell(line, v)] }])
    end
  end
end