Conditions | 2 |
Total Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | require 'csv' |
||
6 | def parse(contents, &block) |
||
7 | options = parser_options.merge({ headers: true }) |
||
8 | csv = CSV.parse(contents, options) |
||
9 | column_names = csv.headers |
||
10 | collection = [] |
||
11 | |||
12 | csv.each do |line| |
||
13 | element = {} |
||
14 | column_names.each do |name| |
||
15 | element[name] = line[name] |
||
16 | end |
||
17 | collection << element |
||
18 | end |
||
19 | |||
20 | return collection.each(&block) if block |
||
21 | collection |
||
22 | end |
||
23 | end |
||
26 |