Class: Msewage::Importer::Importers::CSV
- Inherits:
-
Base
- Object
- Base
- Msewage::Importer::Importers::CSV
show all
- Defined in:
- lib/msewage-importer/importers/csv.rb
Instance Method Summary
collapse
Methods inherited from Base
factory, importers, #initialize, load_importers, type
Instance Method Details
#build_hash(headers, sources) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/msewage-importer/importers/csv.rb', line 18
def build_hash(, sources)
[].tap do |array_with_sources|
sources.each do |line|
source = {}
line.each_with_index do |data, i|
source[[i]] = data
end
array_with_sources.push(source)
end
end
end
|
#import ⇒ Object
8
9
10
11
12
|
# File 'lib/msewage-importer/importers/csv.rb', line 8
def import
sources = read_file
= sources.shift
build_hash(, sources)
end
|
#read_file ⇒ Object
14
15
16
|
# File 'lib/msewage-importer/importers/csv.rb', line 14
def read_file
::CSV.parse(File.read(file_name))
end
|