Class: Importer::Parser::Csv

Inherits:
Base
  • Object
show all
Defined in:
lib/importer/parser/csv.rb

Overview

CSV parser

Instance Attribute Summary

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

#initialize, run

Constructor Details

This class inherits a constructor from Importer::Parser::Base

Instance Method Details

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/importer/parser/csv.rb', line 7

def run
  @data = []

  data = CSV.read(@file, :skip_blanks => true)

  unless data.empty?
    attributes = data.shift
    @data = data.map do |values|
      Hash[*attributes.zip(values).flatten]
    end
  end

  @data
end