3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/remote_table/file/roo_spreadsheet.rb', line 3
def each_row(&block)
oo = roo_klass.new(path, nil, :ignore)
oo.default_sheet = sheet.is_a?(Numeric) ? oo.sheets[sheet] : sheet
column_references = Hash.new
if == false
for col in (1..oo.last_column)
column_references[col] = col - 1
end
elsif .is_a? Array
for col in (1..oo.last_column)
column_references[col] = [col - 1]
end
else
for col in (1..oo.last_column)
column_references[col] = oo.cell(, col)
column_references[col] = oo.cell( - 1, col) if column_references[col].blank? end
end
first_data_row.upto(oo.last_row) do |raw_row|
ordered_hash = ActiveSupport::OrderedHash.new
for col in (1..oo.last_column)
next if column_references[col].blank?
ordered_hash[column_references[col]] = oo.cell(raw_row, col).to_s.gsub(/<[^>]+>/, '').strip
end
yield ordered_hash if keep_blank_rows or ordered_hash.any? { |k, v| v.present? }
end
end
|