| Total Complexity | 2 |
| Total Lines | 19 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | require 'csv' |
||
| 5 | class NamedColumnsParser < CsvParser |
||
| 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 |
||
| 24 | end |
||
| 26 |