trotter (owner)

Revisions

gist: 66628 Download_button fork
public
Public Clone URL: git://gist.github.com/66628.git
Embed All Files: show embed
parse_jenn_hlm.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'rubygems'
require 'fastercsv'
require 'ruby-debug'
 
data = FasterCSV.read(ARGV[0], :headers => :first_row)
columns = %w( PCI5 PCI6 PCI7 PCI9 PCI11 PCI13
PCI15 PCI21 PCI24
)
 
headers_extra = columns.map { |col| "p_#{col}" }
puts (data.headers + headers_extra).join(',')
previous_row = nil
 
data.each do |row|
  if previous_row && row['subID'] =~ /^ *$/
    line_one_extra = columns.map {|col| row[col]}
    line_two_extra = columns.map {|col| previous_row[col]}
    puts (previous_row.fields + line_one_extra).map{|col| %Q["#{col}"]}.join(',')
    puts (row.fields + line_two_extra).map{|col| %Q["#{col}"]}.join(',')
  elsif previous_row && previous_row['subID'] !~ /^ *$/
    bogus_line_extra = columns.map {|col| ' '}
    puts (previous_row.fields + bogus_line_extra).map{|col| %Q["#{col}"]}.join(',')
  end
  previous_row = row
end
 
if previous_row['subID'] !~ /^ *$/
  bogus_line_extra = columns.map {|col| ' '}
  puts (previous_row.fields + bogus_line_extra).map{|col| %Q["#{col}"]}.join(',')
end