Module: RemoteTable::RooSpreadsheet

Defined in:
lib/remote_table/file/roo_spreadsheet.rb

Instance Method Summary collapse

Instance Method Details

#each_row(&block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/remote_table/file/roo_spreadsheet.rb', line 3

def each_row(&block)
  headers = {}
  oo = roo_klass.new(path, nil, :ignore)
  oo.default_sheet = sheet.is_a?(Numeric) ? oo.sheets[sheet] : sheet
  for col in (1..oo.last_column)
    headers[col] = oo.cell(header_row, col)
    headers[col] = oo.cell(header_row - 1, col) if headers[col].blank? # look up
  end
  first_data_row.upto(oo.last_row) do |row|
    values = {}
    for col in (1..oo.last_column)
      values[headers[col]] = oo.cell(row, col).to_s.gsub(/<[^>]+>/, '').strip
    end
    yield HashWithIndifferentAccess.new(values)
  end
end