Class: XX::Parse

Inherits:
Object show all
Defined in:
lib/extensions/parse.rb

Class Method Summary collapse

Class Method Details

.csv_to_array(file_location) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/extensions/parse.rb', line 5

def self.csv_to_array(file_location)
  csv = CSV::parse(File.open(file_location, 'r') {|f| f.read })
  fields = csv.shift
  csv.map do |record|
    Hash[*(0..(fields.length - 1)).map do |index|
      [fields[index],record[index].to_s]
    end.flatten ]
  end
end