Class: CsvMap
- Inherits:
-
Object
- Object
- CsvMap
- Defined in:
- lib/csv_as_map.rb
Class Method Summary collapse
- .create_header_hash(header_array) ⇒ Object
- .foreach(path, &block) ⇒ Object
- .parse(row_array, header) ⇒ Object
Class Method Details
.create_header_hash(header_array) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/csv_as_map.rb', line 22 def self.create_header_hash(header_array) header = Hash.new count = 0 header_array.each do |token| header[token] = count count = count + 1 end header end |
.foreach(path, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/csv_as_map.rb', line 6 def self.foreach(path,&block) header = nil FasterCSV.foreach(path) do |row| if ! header header = self.create_header_hash(row) next end row_map = parse(row,header) yield row_map end end |
.parse(row_array, header) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/csv_as_map.rb', line 34 def self.parse(row_array,header) row_hash = Hash.new header.each do |name,index| row_hash[name] = row_array[index] end row_hash end |